Documentation ¶
Index ¶
- Constants
- Variables
- func AssertReadable(file string) error
- func FindFiles(fileNames ...string) (string, error)
- func FindInDir(dir string, fileNames ...string) (string, error)
- func HasReadPerm(info fs.FileInfo) error
- func IsHex(s string) bool
- func MapFiles(docRoot string) ([]string, error)
- func MockClearFS()
- func MockReader(file string) ([]byte, error)
- func MockTester(file string) error
- func MockWriteFile(fname string, fdata []byte, isReadable bool, ferr error)
- func ParseYAML[T any](file string, obj *T) error
- func ReadFile(file string) ([]byte, error)
- func SetReader(r func(string) ([]byte, error))
- func SetTester(t func(string) error)
- func ValidatePasswordHash(hash string) error
- type Config
- type Logger
- type MockFile
Constants ¶
View Source
const ( DefaultAPIHost = "0.0.0.0" DefaultAPIPort = "8080" DefaultDocRoot = "assets" DefaultDBRoot = "db" DefaultShutdownTimeout = 5 )
Variables ¶
View Source
var ( FileNotFound = "file not found" ErrInvalidEnv = fmt.Errorf("invalid environment") ErrUnknownOpt = fmt.Errorf("unknown option") )
View Source
var ( ErrParamEmpty = fmt.Errorf("parameter is empty") ErrParamTooLong = fmt.Errorf("parameter is too long") ErrParamBadFormat = fmt.Errorf("parameter format is invalid") )
View Source
var ( MockFS = make(map[string]MockFile) MockTesterPerms = false )
View Source
var ( MockTestConfig = []byte(`env: prod debug: true tls_cert_file: "/tmp/cuttle_cert.cert" tls_key_file: "/tmp/cuttle_key.pem" api_host: 127.0.0.1 api_port: "9090" db_root: /tmp/db shutdown_timeout: 0`) MockTestCert = []byte(`-----BEGIN CERTIFICATE----- MIIF1TCCA72gAwIBAgIUQFIA0nAR355w7z6OfjUI3TY5K1EwDQYJKoZIhvcNAQEN BQAwejELMAkGA1UEBhMCVVMxEDAOBgNVBAgMB0dlb3JnaWExEDAOBgNVBAcMB0F0 bGFudGExEDAOBgNVBAoMB1Rlc3RMQUIxDDAKBgNVBAsMA0RldjETMBEGA1UEAwwK Q3V0dGxlIEFwcDESMBAGCSqGSIb3DQEJARYDbmFuMB4XDTI0MDcyMzIxNTkzMVo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AQENBQADggIBAKBqvFWSeJwmfCTo/MGUO36SatJ7wAj4 tM+CBMaxZrI5EXKl8Fc6Im93yDEu3wubkCSrv6y3UGXzKqrXdAf0TzIL+BK/HfLC ygQQZUFakywBwCbzxoP+scz7rikwzP7MS/mZIHDPYSsuzLVKJXFqgzP6MbZEiETb c/XKG0ReEy+ruEd4r9yKH0vuBHz5RG483gMsvC0hhQTfj6dkJWKz9Pmo0dvKcAN1 7YQX8XteKEjUUDBXI+zoOSKnXOdSMzDnH0ndRxoqiJcZjKS+s5aEgCTf5pME6Va9 899pcwZBBsOpYI1kqLcTlykcWzKeN8Id9TM9kgy04YJGUcJlW6QMDQGxSzunopim tTgGFNswPaaODkPPoEhBVD6TEyZBgwQuchvbN6b4FEjyOiVf23+KgyVbzKH2L0TR VoeHwFLXFxuCt074ExityQK6arbi3GiZwbOcmGJhjLt6WNiy2Ew5KmFUBX2Mgz+b KM8UyRONFQDwTj+L7JWoRfOTtXBly1qbccME12nbnZzlUjBDPspqxEvh5WoJEgnm p2P/F6tRqVkDZJdNoF/EZgXDYKyEPmNVjVFO8FFqYEq7xEGmnBtlXZKl48pH7w53 x8r9seUwowiZQkrRz6A3RyFPXtgJakisEsAjknz+9Cn+Mq5kkY7pXDwwDRl6LIuY prDLZKx0Xw3n -----END CERTIFICATE-----`) MockTestKey = []byte(`-----BEGIN PRIVATE KEY----- MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC2s7qdhAJSvw4Y 2rUtC0Q8dC04nid3fJnBWB8ydFQTjUN3WokKhuOaq6tY6IePbNa/p/res6YRcvfL 6LhkNyU2VQfS+IihdZmdiI7V33KO96SistXz2MBrYHZSGrkBVY+Y7tWzYFnHVk6R lCAmxuEaeBb1r+ja2mFSM1YHlyArJX+tmTyTQ8LkFrcXOnqEoNoNNfCtlBGVi9pj PmNlSo6LdZGF5pBeHGYHAxZdxIPUK00zRwchHRFwhYisOowfOpxD17KE+et3pRC8 TJg3vNdd16AlrtKa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b7/qr+NmzklORlGP9fYMzp3uh5q/IqZRvzytjjuda8+tfQwqnWlAEelnZfu3I X/Je6kONhejwW0i6ngaoCLpCGWLSFcaB+kYkITX+nAm7j4wso5i4VoHMg1wTm9e7 si53XmHAHcQ5lAmvmATHsExw2JwcL8jxhs+bn8CXqiBfIFS8jU2VxmbG41YZ426R +XmLa+R8mRnSnPgQH2R/C6NEOYaZ9RQqonbBYOQl1e36uIrFt3X7nPcM5exdTgrI OvP7o5q7M01K9Mp0MLTpifpdArrhBkQe5yadVJnuob0hu8BcvrJoZBjThAZY/5lw wQKCAQBH8T841Yug/8sCnv6aVBfbBh2sJQC9UX+qYvVpap3WsmQ/OmRyUfZURBVa SPD/II+4TojbbSebvjECUwIQgbPUDFqXowFqaCh/ToBemF7vxSPkJJI0mJBs5R9L 3jP0TTmm0sjTRFixE61GN81kc7M6eW8jNAtjruPXKBJbCt2r/Zp4NAwnVKm+xYN+ YMGxbuXcrXmDwi3HWtTSrvQ7ugy4GM8xh5A9LO23put2g4GnmfKJslejWynzbGoz bvBOUno4U5SvrTs2IBvkmZAMnYO9+B1j7NXPOYUXqBNHLmxJW6wYXvGMRePEjHmn R3zzWGC9q0+JqmI7jKW/g9d5TBvy -----END PRIVATE KEY-----`) )
Functions ¶
func AssertReadable ¶
CheckReadability returns nil if file is readable.
func FindFiles ¶
FindFiles returns the location of the config file if found. Returns "" and an error if not.
func FindInDir ¶
FindInDir returns the contents of the first file found in the directory. dir should not contain a trailing "/". If no file is found, return FileNotFound.
func HasReadPerm ¶
HasReadPerm returns nil if the app has read permission to the file.
func MockClearFS ¶
func MockClearFS()
func MockReader ¶
func MockTester ¶
func MockWriteFile ¶
MockWriteFile creates a new MockFile and appends it to the MockTesterFiles slice. If the file already exists, it will update the file with the new data.
func ValidatePasswordHash ¶
Types ¶
type Config ¶
type Config struct { Env string `yaml:"env,omitempty"` Debug bool `yaml:"debug,omitempty"` TLSCertFile string `yaml:"tls_cert_file,omitempty"` TLSKeyFile string `yaml:"tls_key_file,omitempty"` APIHost string `yaml:"api_host,omitempty"` APIPort string `yaml:"api_port,omitempty"` DBRoot string `yaml:"db_root,omitempty"` // DBRoot is the root path for the database. DocRoot string `yaml:"doc_root,omitempty"` // DocRoot is the document root path for the serving static html files. ShutdownTimeout int `default:"5" yaml:"shutdown_timeout,omitempty"` // in seconds Secret string `yaml:"secret,omitempty"` }
func DefaultConfig ¶
func DefaultConfig() *Config
Click to show internal directories.
Click to hide internal directories.