Documentation ¶
Index ¶
- Constants
- func InitializeServerComponents(cfg *viper.Viper, config *ServerConfig) error
- func LoadServerConfig(altCfgFilePath string) (*viper.Viper, error)
- func SetupAPIRouter(config *ServerConfig)
- type DisplayUser
- type ErrorResponse
- type ListResponse
- type ProductCreationInput
- type ServerConfig
- type UserLoginInput
- type WebhookExecutor
Constants ¶
const ( DefaultImageStorageProvider = "local" DefaultDatabaseProvider = "postgres" )
const ( // DefaultLimit is the number of results we will return per page if the user doesn't specify another amount DefaultLimit = 25 // MaxLimit is the maximum number of objects Dairycart will return in a response MaxLimit = 50 )
const ( ProductCreatedWebhookEvent = "product_created" ProductUpdatedWebhookEvent = "product_updated" ProductArchivedWebhookEvent = "product_archived" )
const ( // ValidURLCharactersPattern represents the valid characters a sku can contain ValidURLCharactersPattern = `[a-zA-Z\-_]+` // NumericPattern repesents numeric values NumericPattern = `[0-9]+` )
Variables ¶
This section is empty.
Functions ¶
func InitializeServerComponents ¶
func InitializeServerComponents(cfg *viper.Viper, config *ServerConfig) error
InitializeServerComponents calls Init on all the relevant server components, and migrates the database.
func SetupAPIRouter ¶
func SetupAPIRouter(config *ServerConfig)
SetupAPIRouter takes a mux router and a database connection and creates all the API routes for the API
Types ¶
type DisplayUser ¶
type DisplayUser struct { ID uint64 `json:"id"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Email string `json:"email"` IsAdmin bool `json:"is_admin"` CreatedOn time.Time `json:"created_on"` UpdatedOn *models.Dairytime `json:"updated_on,omitempty"` ArchivedOn *models.Dairytime `json:"archived_on,omitempty"` }
DisplayUser represents a Dairycart user we can return in responses TODO: the main reason for doing this is so we don't end up returning the password hash to the user, but there's bound to be a way to reuse that struct
type ErrorResponse ¶
ErrorResponse is a handy struct we can respond with in the event we have an error to report
type ListResponse ¶
type ListResponse struct { Count uint64 `json:"count"` Limit uint8 `json:"limit"` Page uint64 `json:"page"` Data interface{} `json:"data"` }
ListResponse is a generic list response struct containing values that represent pagination, meant to be embedded into other object response structs
type ProductCreationInput ¶
type ProductCreationInput struct { models.Product Options []models.ProductOption `json:"options"` }
ProductCreationInput is a struct that represents a product creation body
type ServerConfig ¶
type ServerConfig struct { Router *chi.Mux DB *sql.DB CookieStore *sessions.CookieStore DatabaseClient database.Storer WebhookExecutor WebhookExecutor ImageStorer images.ImageStorer }
func BuildServerConfig ¶
func BuildServerConfig(config *viper.Viper) (*ServerConfig, error)
type UserLoginInput ¶
UserLoginInput represents the payload used to log in a Dairycart user