add basic auth for webapi
This commit is contained in:
@ -54,9 +54,11 @@ type ProfilingConfig struct {
|
||||
}
|
||||
|
||||
type APIConfig struct {
|
||||
Addr string `json:"addr"`
|
||||
PathPrefix string `yaml:"pathPrefix,omitempty" json:"pathPrefix,omitempty"`
|
||||
AccessLog bool `yaml:"accesslog,omitempty" json:"accesslog,omitemtpy"`
|
||||
Addr string `json:"addr"`
|
||||
PathPrefix string `yaml:"pathPrefix,omitempty" json:"pathPrefix,omitempty"`
|
||||
AccessLog bool `yaml:"accesslog,omitempty" json:"accesslog,omitempty"`
|
||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||
Auther string `yaml:",omitempty" json:"auther,omitempty"`
|
||||
}
|
||||
|
||||
type TLSConfig struct {
|
||||
|
@ -35,7 +35,7 @@ func ParseAuther(cfg *config.AutherConfig) auth.Authenticator {
|
||||
return auth.NewMapAuthenticator(m)
|
||||
}
|
||||
|
||||
func autherFromAuth(au *config.AuthConfig) auth.Authenticator {
|
||||
func ParseAutherFromAuth(au *config.AuthConfig) auth.Authenticator {
|
||||
if au == nil || au.Username == "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"github.com/go-gost/gost/pkg/service"
|
||||
)
|
||||
|
||||
func ParseService(cfg *config.ServiceConfig) (*service.Service, error) {
|
||||
func ParseService(cfg *config.ServiceConfig) (service.Servicer, error) {
|
||||
if cfg.Listener == nil {
|
||||
cfg.Listener = &config.ListenerConfig{
|
||||
Type: "tcp",
|
||||
@ -47,7 +47,7 @@ func ParseService(cfg *config.ServiceConfig) (*service.Service, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auther := autherFromAuth(cfg.Listener.Auth)
|
||||
auther := ParseAutherFromAuth(cfg.Listener.Auth)
|
||||
if cfg.Listener.Auther != "" {
|
||||
auther = registry.Auther().Get(cfg.Listener.Auther)
|
||||
}
|
||||
@ -84,7 +84,7 @@ func ParseService(cfg *config.ServiceConfig) (*service.Service, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auther = autherFromAuth(cfg.Handler.Auth)
|
||||
auther = ParseAutherFromAuth(cfg.Handler.Auth)
|
||||
if cfg.Handler.Auther != "" {
|
||||
auther = registry.Auther().Get(cfg.Handler.Auther)
|
||||
}
|
||||
|
Reference in New Issue
Block a user