51
config/config.go
Normal file
51
config/config.go
Normal 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
6
config/variables.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
var (
|
||||
ServiceName = "account"
|
||||
ServiceVersion = "0.0.1"
|
||||
)
|
Reference in New Issue
Block a user