config

package
v0.0.0-...-16c2cb2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Roles
	ROLE_COURSEADMIN  uint = 1
	ROLE_FIELDMANAGER uint = 2
	ROLE_TEACHER      uint = 3
	ROLE_STUDENT      uint = 4
	// Grade types
	GRADETYPE_NONE    uint = 1
	GRADETYPE_NOTE    uint = 2
	GRADETYPE_PERCENT uint = 3
)
View Source
const VERSION string = "0.8.1"

Version of the API

Variables

This section is empty.

Functions

func ToFile

func ToFile(path string, config *APIConfig)

Saves the configuration to a file

Types

type APIConfig

type APIConfig struct {
	Host                string                     `yaml:"host"`                // Host is the address of the server
	Port                int                        `yaml:"port"`                // Port is the port of the server
	AuthConfig          AuthConfig                 `yaml:"auth"`                // AuthConfig is the configuration for authentication
	AutoMigrate         bool                       `yaml:"autoMigrate"`         // AutoMigrate is a flag to determine if the database should be migrated automatically
	Connect             bool                       `yaml:"connect"`             // Connect is a flag to determine if the database should be connected automatically
	DBConnectionStr     string                     `yaml:"dbConnectionStr"`     // DBConnectionStr is the connection string for the database
	AllowedDomains      []string                   `yaml:"allowedDomains"`      // AllowedDomains is the list of allowed domains for new users
	ExamTypes           []string                   `yaml:"examTypes"`           // ExamTypes is the list of exam types
	ExamEvaluationTypes []ExamEvaluationTypeConfig `yaml:"examEvaluationTypes"` // EvalTypes is the list of evaluation types
	GradeTypes          []GradeTypeConfig          `yaml:"gradeTypes"`          // GradeTypes is the list of grade types
	States              []string                   `yaml:"states"`              // States is the list of states
	CurriculumTypes     []CurriculumTypeConfig     `yaml:"curriculumTypes"`     // CurriculumTypes is the list of curriculum types
	Roles               []RoleConfig               `yaml:"roles"`               // Roles is the list of roles
	MockData            bool                       `yaml:"mockData"`            // Add MockData at startup
	Cors                CorsConfig                 `yaml:"cors"`                // Cors is the configuration for CORS
	MaxBodySize         string                     `yaml:"maxBodySize"`         // BodySize is the maximum size of the request body
	RateLimit           RateLimitConfig            `yaml:"rateLimit"`           // RateLimit is the configuration for rate limiting
	LogLevel            string                     `yaml:"logLevel"`            // LogLevel is the preferred log level
	// contains filtered or unexported fields
}

APIConfig is used to define the configuration of the API

func FromFile

func FromFile(path string) *APIConfig

Loads the configuration from a file Attempts to write default configuration to file if file does not exist

func NewAPIConfig

func NewAPIConfig() *APIConfig

Returns a new configuration with default values This is used to create the config file if it does not exist

func (*APIConfig) FromEnv

func (c *APIConfig) FromEnv()

Overwrites the current configuration with environment variables

func (*APIConfig) GetEchoCORSConfig

func (c *APIConfig) GetEchoCORSConfig() middleware.CORSConfig

Returns the echo CORS configuration based on the API configuration

func (*APIConfig) GetEchoLoggerConfig

func (c *APIConfig) GetEchoLoggerConfig() middleware.RequestLoggerConfig

Returns the echo logger configuration based on the API configuration

func (*APIConfig) GetRateLimitConfig

func (c *APIConfig) GetRateLimitConfig() middleware.RateLimiterConfig

Returns the rate limiter configuration based on the API configuration

func (*APIConfig) Logger

func (c *APIConfig) Logger() *e.ApiLogger

Initializes the logger with the correct log level

func (*APIConfig) ServerAddress

func (c *APIConfig) ServerAddress() string

Returns the server address as a string

func (*APIConfig) ShowBrand

func (c *APIConfig) ShowBrand()

Shows the brand in the console application It displays the logo on the console and information about the API like version and host / port

type AuthConfig

type AuthConfig struct {
	Enabled              bool   `yaml:"enabled"`              // Enabled is a flag to determine if authentication is enabled
	OAuthKeyDiscoveryURL string `yaml:"oAuthKeyDiscoveryURL"` // OAuthKeyDiscoveryURL is the URL to discover the OAuth keys
}

Configuration for Authentication

type CorsConfig

type CorsConfig struct {
	AllowedOrigins []string `yaml:"allowedOrigins"` // AllowedOrigins is the list of allowed origins
	AllowedHeaders []string `yaml:"allowedHeaders"` // AllowedHeaders is the list of allowed headers
}

Configuration for CORS

type CurriculumTypeConfig

type CurriculumTypeConfig struct {
	Description   string `yaml:"description"`
	DurationYears uint   `yaml:"durationyears"`
}

Predefined curriculum types

type ExamEvaluationTypeConfig

type ExamEvaluationTypeConfig struct {
	Code        string `yaml:"code"`        // code is the code of the evaluation type
	Description string `yaml:"description"` // description is the description of the evaluation type
}

Predefined exam evaluation types

type GradeTypeConfig

type GradeTypeConfig struct {
	Id          uint   `yaml:"id"`          // Id of the grade type
	Description string `yaml:"description"` // Description of the grade type
}

type RateLimitConfig

type RateLimitConfig struct {
	Burst  int `yaml:"burst"`  // Burst is the maximum number of requests that can be made in a second (RPS)
	Rate   int `yaml:"rate"`   // Rate is the usual number of requests that can be made in a second (RPS)
	Expiry int `yaml:"expiry"` // Expiry is the time in seconds until the rate limit is reset
}

type RoleConfig

type RoleConfig struct {
	Id        uint   `yaml:"id"`        // Id of the role
	Name      string `yaml:"name"`      // Name of the role
	ClaimName string `yaml:"claimName"` // Name of the claim in the JWT
}

Configuration for a role

Jump to

Keyboard shortcuts

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