migrate from github
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package config_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/XingfenD/yoresee_doc/internal/status"
|
||||
"github.com/XingfenD/yoresee_doc/pkg/storage"
|
||||
)
|
||||
|
||||
type ConfigService struct {
|
||||
SystemRegisterMode func() string `consul:"system.security.register_mode,default=invite"`
|
||||
SystemRegisterLimit func() bool `consul:"system.security.register_limit"`
|
||||
}
|
||||
|
||||
func NewConfigService() *ConfigService {
|
||||
if !storage.ConsulEnabled() {
|
||||
return nil
|
||||
}
|
||||
s := &ConfigService{}
|
||||
if err := storage.BindConsulConfig(s, storage.Consul); err != nil {
|
||||
panic("consul service init failed")
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *ConfigService) GetSystemRegisterMode(ctx context.Context) string {
|
||||
return s.SystemRegisterMode()
|
||||
}
|
||||
|
||||
func (s *ConfigService) GetSystemRegisterLimit(ctx context.Context) bool {
|
||||
return s.SystemRegisterLimit()
|
||||
}
|
||||
|
||||
func (s *ConfigService) Set(ctx context.Context, key, value string) error {
|
||||
if !storage.ConsulEnabled() {
|
||||
return status.GenErrWithCustomMsg(status.StatusServiceInternalError, "consul is not enabled")
|
||||
}
|
||||
return storage.Consul.Set(ctx, key, value)
|
||||
}
|
||||
|
||||
var ConfigSvc *ConfigService
|
||||
|
||||
func InitConfigService() {
|
||||
ConfigSvc = NewConfigService()
|
||||
}
|
||||
Reference in New Issue
Block a user