common

package
v0.0.0-...-d10edbe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HistoryTopic      = "history"
	NotificationTopic = "notification"
	EmailSent         = "email_sent"
)
View Source
const ConfigFolder = "/etc/microsaas/"

Variables

This section is empty.

Functions

func GinLogFormatter

func GinLogFormatter(param gin.LogFormatterParams) string

func Healthcheck

func Healthcheck(g *gin.Context)

Healthcheck is the REST handler for polling whether the application is available. @Summary Health check endpoint of the Schedlue.me app @Schemes @Description Returns the status and version of the application @Accept json @Produce json @Success 200 {object} common.Health @Router /healthcheck [get]

func LoggerMiddleware

func LoggerMiddleware(logger *log.Logger) gin.HandlerFunc

func ValidationMessages

func ValidationMessages(err error) []string

ValidationMessages is a function to convert Gin-Gonic validation error to human readable.

Types

type AnalyticsConfig

type AnalyticsConfig struct {
	StatsigServerKey string `mapstructure:"STATSIG_SERVER_SECRET_KEY"`
}

type AppConfig

type AppConfig struct {
	DB        *RDBConfig
	Auth      *AuthConfig
	Log       *LogConfig
	Mail      *MailConfig
	Web       *WebConfig
	Analytics *AnalyticsConfig
	Path      string
}

AppConfig is the holder of all configurations for the application

func InitApp

func InitApp(path string) *AppConfig

InitApp sets up the app including configuration management and logging

func (AppConfig) PathFor

func (c AppConfig) PathFor(file string) string

type AuthConfig

type AuthConfig struct {
	JWTSecret          string `mapstructure:"JWT_SIGN_SECRET"`
	JWTExp             int    `mapstructure:"JWT_EXPIRATION_HOURS"`
	JWTSecure          bool   `mapstructure:"JWT_COOKIE_SECURE"`
	TLSCert            string `mapstructure:"TLS_CERT_PATH"`
	TLSKey             string `mapstructure:"TLS_KEY_PATH"`
	FrontendRoot       string `mapstructure:"FRONTEND_ROOT"`
	BackendRoot        string `mapstructure:"BACKEND_ROOT"`
	RecaptchaAppCreds  string `mapstructure:"GOOGLE_APPLICATION_CREDENTIALS"`
	RecaptchaProjectID string `mapstructure:"GOOGLE_PROJECT_ID"`
	RecaptchaKey       string `mapstructure:"GOOGLE_RECAPTCHA_KEY"`
	GoogleKey          string `mapstructure:"GOOGLE_AUTH_KEY"`
	GoogleSecret       string `mapstructure:"GOOGLE_AUTH_SECRET"`
	FacebookKey        string `mapstructure:"FACEBOOK_AUTH_KEY"`
	FacebookSecret     string `mapstructure:"FACEBOOK_AUTH_SECRET"`
}

AuthConfig is a configuration of the authentication.

type EmailData

type EmailData struct {
	From    string `json:"from"`
	To      string `json:"to"`
	Subject string `json:"subject"`
	Body    string `json:"body"`
}

type Event

type Event struct {
	ID   uuid.UUID   `json:"id"`
	Type string      `json:"type"`
	Time time.Time   `json:"time"`
	Data interface{} `json:"data"`
	User uuid.UUID   `json:"user"`
}

type Health

type Health struct {
	Status  string `json:"status"`
	Version string `json:"version"`
}

Health is a JSON response for healthcheck request

type LogConfig

type LogConfig struct {
	LogLevel  string `mapstructure:"LOG_LEVEL"`
	PrettyLog bool   `mapstructure:"PRETTY_LOG"`
}

LogConfig is a configuration of the logging.

type MailConfig

type MailConfig struct {
	ApplicationName string `mapstructure:"APPLICATION_NAME"`
	NoReplyAddress  string `mapstructure:"MAIL_NO_REPLY_ADDRESS"`
	SMTPAddress     string `mapstructure:"MAIL_SMTP_ADDRESS"`
	SMTPUser        string `mapstructure:"MAIL_SMTP_USER"`
	SMTPPassword    string `mapstructure:"MAIL_SMTP_PASSWORD"`
	SMTPPort        int    `mapstructure:"MAIL_SMTP_PORT"`
}

MailConfig is a configuration of e-mail massaging.

type RDBConfig

type RDBConfig struct {
	Host            string        `mapstructure:"DB_HOST"`
	Port            int           `mapstructure:"DB_PORT"`
	DBName          string        `mapstructure:"DB_NAME"`
	Username        string        `mapstructure:"DB_USER"`
	Password        string        `mapstructure:"DB_PASS"`
	MaxIdleConns    int           `mapstructure:"DB_MAX_IDLE_CONN"`
	MaxOpenConns    int           `mapstructure:"DB_MAX_OPEN_CONN"`
	ConnMaxLifetime time.Duration `mapstructure:"DB_CONN_LIFETIME"`
	SSLMode         string        `mapstructure:"DB_SSL_MODE"`
	SSLCert         string        `mapstructure:"DB_SSL_CERT"`
}

RDBConfig is a configuration of the relational database.

func (RDBConfig) String

func (c RDBConfig) String() string

type RecaptchaResponse

type RecaptchaResponse struct {
	Success     bool     `json:"success"`
	Score       float64  `json:"score"`
	Action      string   `json:"action"`
	ChallengeTS string   `json:"challenge_ts"`
	Hostname    string   `json:"hostname"`
	ErrorCodes  []string `json:"error-codes"`
}

RecaptchaResponse is a JSON response from Google ReCaptcha.

type RecaptchaValidator

type RecaptchaValidator struct {
	// contains filtered or unexported fields
}

RecaptchaValidator is a struct for validating captcha using Google's ReCapthca validator

func NewRecaptchaValidator

func NewRecaptchaValidator(projectID string, recaptchaKey string, keyFile string) (*RecaptchaValidator, error)

NewRecaptchaValidator is a function creating a new `RecaptchaValidator` based on the API secret

func (RecaptchaValidator) Close

func (v RecaptchaValidator) Close()

func (RecaptchaValidator) Verify

func (v RecaptchaValidator) Verify(token string) error

Verify is a method of `RecaptchaValidator` verifying the captch token from the frontend

type StatusMessage

type StatusMessage struct {
	Message string
}

StatusMessage is a generic JSON response containing the message for the HTTP status.

func ValidationMessage

func ValidationMessage(err error) StatusMessage

ValidationMessage is a function to convert Gin-Gonic validation errors to `StatusMessage`.

type WebConfig

type WebConfig struct {
	Port int `mapstructure:"PORT"`
}

WebConfig is a configuration of the web application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL