more cleanup
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0) (push) Successful in 41s
Publish Docker Image / docker (ubuntu-latest, 2.44.0) (push) Successful in 1m0s

This commit is contained in:
Lee
2024-06-15 06:33:46 +01:00
parent 3f5755d6b5
commit e9d6954e79
6 changed files with 17 additions and 11 deletions

View File

@ -5,27 +5,27 @@ import (
"strconv"
)
// GetMongoConnectionString returns the MongoDB connection string from the environment or a default value.
// Returns the MongoDB connection string from the environment or a default value.
func GetMongoConnectionString() string {
return getEnv("MONGO_URI", "mongodb://localhost:27017")
}
// GetPasteIDLength returns the paste ID length from the environment or a default value.
// Returns the paste ID length from the environment or a default value.
func GetPasteIDLength() int {
return getIntEnv("PASTE_ID_LENGTH", 12)
}
// GetMaxPasteLength returns the maximum paste length from the environment or a default value.
// Returns the maximum paste length from the environment or a default value.
func GetMaxPasteLength() int {
return getIntEnv("MAX_PASTE_LENGTH", 5000000)
}
// EnableMetrics returns whether to enable metrics or not (default: false).
// Returns whether to enable metrics or not (default: false).
func EnableMetrics() bool {
return getEnv("ENABLE_METRICS", "false") == "true"
}
// getEnv returns the environment variable value or a default value if not set.
// Returns the environment variable value or a default value if not set.
func getEnv(key, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
@ -33,7 +33,7 @@ func getEnv(key, defaultValue string) string {
return defaultValue
}
// getIntEnv returns the integer value of an environment variable or a default value if not set or invalid.
// Returns the integer value of an environment variable or a default value if not set or invalid.
func getIntEnv(key string, defaultValue int) int {
valueStr := getEnv(key, strconv.Itoa(defaultValue))
value, err := strconv.Atoi(valueStr)

View File

@ -2,7 +2,9 @@ package errors
import "errors"
var ErrPasteTooLarge = errors.New("paste is too large")
var ErrUnableToGeneratePasteKey = errors.New("unable to generate paste key")
var ErrUnableToConnectToDatabase = errors.New("unable to connect to database")
var ErrInvalidPasteID = errors.New("invalid paste id")
var (
ErrPasteTooLarge = errors.New("paste is too large")
ErrUnableToGeneratePasteKey = errors.New("unable to generate paste key")
ErrUnableToConnectToDatabase = errors.New("unable to connect to database")
ErrInvalidPasteID = errors.New("invalid paste id")
)

View File

@ -29,6 +29,7 @@ func InitMetricsUpdater() {
}()
}
// Updates the metrics
func updateMetrics() {
fmt.Println("Updating metrics...")
ctx := context.Background()

View File

@ -13,6 +13,7 @@ import (
stringUtils "cc.fascinated/paste/internal/utils"
)
// Gets a paste by its ID
func GetPaste(id string) (*db.PasteModel, error) {
fmt.Printf("Getting paste \"%s\"...\n", id)
before := time.Now()

View File

@ -6,7 +6,7 @@ import (
"github.com/labstack/echo/v4"
)
// InitRoutes initializes the routes for the application.
// Initializes the routes for the application.
func InitRoutes(router *echo.Echo) {
if config.EnableMetrics() { // Check if metrics are enabled
router.GET("/metrics", echoprometheus.NewHandler())

View File

@ -7,6 +7,7 @@ import (
"github.com/labstack/echo/v4"
)
// Renders the paste content
func renderPaste(c echo.Context) error {
// Get the paste ID
id := c.Param("id")
@ -29,6 +30,7 @@ func renderPaste(c echo.Context) error {
})
}
// Renders the raw paste content
func renderPasteRaw(c echo.Context) error {
// Get the paste ID
id := c.Param("id")