initial import
Some checks failed
build / test (push) Failing after 5s
build / lint (push) Failing after 6s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-09-26 19:45:39 +03:00
parent c08ab26cf9
commit 973f9ac822
21 changed files with 3074 additions and 0 deletions

51
config/config.go Normal file
View File

@@ -0,0 +1,51 @@
package config
import (
"fmt"
"net"
"strconv"
service "go.unistack.org/cms-service"
)
type App struct {
TLSCrt string `flag:"name=account.tls_crt,desc='tls crt file'"`
TLSKey string `flag:"name=account.tls_key,desc='tls key file'"`
Address string `flag:"name=account.address,desc='listen address',default=':0'"`
}
type Config struct {
App *App
Storage *service.ConfigStorage
Logger *service.ConfigLogger
Service *service.ConfigService
Core *service.ConfigCore
}
func NewConfig() *Config {
return &Config{
Service: &service.ConfigService{
Name: ServiceName,
Version: ServiceVersion,
},
}
}
func (c *App) Validate() error {
_, port, err := net.SplitHostPort(c.Address)
if err != nil {
return fmt.Errorf("invalid address: %s, err: %w", c.Address, err)
}
if port == "443" && (c.TLSCrt == "" || c.TLSKey == "") {
return fmt.Errorf("use secured connection without tls crt/key")
}
if v, err := strconv.Atoi(port); err != nil {
return fmt.Errorf("invalid address/port: %v", c.Address)
} else if v < 0 || v > 65535 {
return fmt.Errorf("invalid address/port: %v", c.Address)
}
return nil
}

6
config/variables.go Normal file
View File

@@ -0,0 +1,6 @@
package config
var (
ServiceName = "account"
ServiceVersion = "0.0.1"
)