add web api

This commit is contained in:
ginuerzh
2022-02-08 23:46:54 +08:00
parent 0fba6d2500
commit f1eaef8d69
22 changed files with 1209 additions and 33 deletions

View File

@ -3,6 +3,7 @@ package config
import (
"encoding/json"
"io"
"sync"
"time"
"github.com/spf13/viper"
@ -20,6 +21,27 @@ func init() {
v.AddConfigPath(".")
}
var (
global = &Config{}
globalMux sync.RWMutex
)
func Global() *Config {
globalMux.RLock()
defer globalMux.RUnlock()
cfg := &Config{}
*cfg = *global
return cfg
}
func SetGlobal(c *Config) {
globalMux.Lock()
defer globalMux.Unlock()
global = c
}
type LogConfig struct {
Output string `yaml:",omitempty" json:"output,omitempty"`
Level string `yaml:",omitempty" json:"level,omitempty"`
@ -31,6 +53,10 @@ type ProfilingConfig struct {
Enabled bool `json:"enabled"`
}
type APIConfig struct {
Addr string `json:"addr"`
}
type TLSConfig struct {
CertFile string `yaml:"certFile,omitempty" json:"certFile,omitempty"`
KeyFile string `yaml:"keyFile,omitempty" json:"keyFile,omitempty"`
@ -163,6 +189,7 @@ type Config struct {
TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Log *LogConfig `yaml:",omitempty" json:"log,omitempty"`
Profiling *ProfilingConfig `yaml:",omitempty" json:"profiling,omitempty"`
API *APIConfig `yaml:",omitempty" json:"api,omitempty"`
}
func (c *Config) Load() error {