config

package
v0.0.0-...-3c55d7b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchRedisDB = fmt.Errorf("no such redis db")
View Source
var ErrNoSuchRpcServer = fmt.Errorf("no such http Rpc Server")
View Source
var ServiceBatchSize int64 = 64

ServiceBatchSize is the number of tasks that a service can read from redis at the same time

Functions

func GetConfigFilePath

func GetConfigFilePath() func(filename string) string

func GetRdsClientByName

func GetRdsClientByName(name string) (rc *redis.Client, err error)

func LoadConfig_FromFile

func LoadConfig_FromFile()

step1: load config from file

func LoadConfig_FromWeb

func LoadConfig_FromWeb()

Types

type ApiSourceHttp

type ApiSourceHttp struct {
	Name    string
	UrlBase string
	Jwt     string
}

the http rpc server

func GetHttpServerByName

func GetHttpServerByName(name string) (server *ApiSourceHttp, err error)

type ConfigHttp

type ConfigHttp struct {
	CORES string
	Port  int64  `env:"Port,default=80"`
	Path  string `env:"Path,default=/"`
	//MaxBufferSize is the max size of a task in bytes, default 10M
	MaxBufferSize int64  `env:"MaxBufferSize,default=10485760"`
	JwtSecret     string `env:"Secret"`
	//AutoAuth should never be true in production
	AutoAuth bool `env:"AutoAuth,default=false"`
}

type ConfigRedis

type ConfigRedis struct {
	Name     string
	Username string `env:"Username"`
	Password string `env:"Password"`
	Host     string `env:"Host,required=true"`
	Port     int64  `env:"Port,required=true"`
	DB       int64  `env:"DB,required=true"`
}

type ConfigSettings

type ConfigSettings struct {
	//{"DebugLevel": 0,"InfoLevel": 1,"WarnLevel": 2,"ErrorLevel": 3,"FatalLevel": 4,"PanicLevel": 5,"NoLevel": 6,"Disabled": 7	  }
	LogLevel int8
	//super user token, this is used to bypass the security check
	//SUToken is designed to allow debugging in production environment without  change the permission table permanently
	SUToken string
}

type Configuration

type Configuration struct {
	ConfigUrl string
	Http      ConfigHttp
	//redis server, format: username:password@address:port/db
	Redis    []*ConfigRedis
	HttpRPC  []*ApiSourceHttp
	Settings ConfigSettings
}
var Cfg Configuration = Configuration{
	ConfigUrl: "",
	Redis:     []*ConfigRedis{},
	Http:      ConfigHttp{CORES: "*", Port: 80, Path: "/", MaxBufferSize: 10485760},
	HttpRPC:   []*ApiSourceHttp{{Name: "doptime", UrlBase: "https://api.doptime.com", Jwt: ""}},
	Settings:  ConfigSettings{LogLevel: 1},
}

set default values

func (Configuration) String

func (c Configuration) String() string

Jump to

Keyboard shortcuts

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