mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-13 17:24:03 +02:00
remove unused code
This commit is contained in:
parent
9889b5a8d3
commit
67b6e40f85
10 changed files with 8 additions and 78 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
||||||
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
"github.com/yusing/go-proxy/internal/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServeMux struct{ *http.ServeMux }
|
type ServeMux struct{ *http.ServeMux }
|
||||||
|
@ -26,8 +25,6 @@ func NewHandler() http.Handler {
|
||||||
mux := NewServeMux()
|
mux := NewServeMux()
|
||||||
mux.HandleFunc("GET", "/v1", v1.Index)
|
mux.HandleFunc("GET", "/v1", v1.Index)
|
||||||
mux.HandleFunc("GET", "/v1/version", v1.GetVersion)
|
mux.HandleFunc("GET", "/v1/version", v1.GetVersion)
|
||||||
// mux.HandleFunc("GET", "/v1/checkhealth", v1.CheckHealth)
|
|
||||||
// mux.HandleFunc("HEAD", "/v1/checkhealth", v1.CheckHealth)
|
|
||||||
mux.HandleFunc("POST", "/v1/login", auth.LoginHandler)
|
mux.HandleFunc("POST", "/v1/login", auth.LoginHandler)
|
||||||
mux.HandleFunc("GET", "/v1/logout", auth.LogoutHandler)
|
mux.HandleFunc("GET", "/v1/logout", auth.LogoutHandler)
|
||||||
mux.HandleFunc("POST", "/v1/logout", auth.LogoutHandler)
|
mux.HandleFunc("POST", "/v1/logout", auth.LogoutHandler)
|
||||||
|
@ -59,9 +56,3 @@ func checkHost(f http.HandlerFunc) http.HandlerFunc {
|
||||||
f(w, r)
|
f(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrap(cfg *config.Config, f func(cfg *config.Config, w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
f(cfg, w, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ var (
|
||||||
|
|
||||||
const tokenExpiration = 24 * time.Hour
|
const tokenExpiration = 24 * time.Hour
|
||||||
|
|
||||||
const jwtClaimKeyUsername = "username"
|
|
||||||
|
|
||||||
func validatePassword(cred *Credentials) error {
|
func validatePassword(cred *Credentials) error {
|
||||||
if cred.Username != common.APIUser {
|
if cred.Username != common.APIUser {
|
||||||
return ErrInvalidUsername.Subject(cred.Username)
|
return ErrInvalidUsername.Subject(cred.Username)
|
||||||
|
@ -114,7 +112,7 @@ func checkToken(w http.ResponseWriter, r *http.Request) (ok bool) {
|
||||||
var claims Claims
|
var claims Claims
|
||||||
token, err := jwt.ParseWithClaims(tokenCookie.Value, &claims, func(t *jwt.Token) (interface{}, error) {
|
token, err := jwt.ParseWithClaims(tokenCookie.Value, &claims, func(t *jwt.Token) (interface{}, error) {
|
||||||
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
return nil, fmt.Errorf("Unexpected signing method: %v", t.Header["alg"])
|
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
|
||||||
}
|
}
|
||||||
return common.APIJWTSecret, nil
|
return common.APIJWTSecret, nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
|
||||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CheckHealth(w http.ResponseWriter, r *http.Request) {
|
|
||||||
target := r.FormValue("target")
|
|
||||||
if target == "" {
|
|
||||||
HandleErr(w, r, ErrMissingKey("target"), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result, ok := health.Inspect(target)
|
|
||||||
if !ok {
|
|
||||||
HandleErr(w, r, ErrNotFound("target", target), http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
json, err := result.MarshalJSON()
|
|
||||||
if err != nil {
|
|
||||||
HandleErr(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
RespondJSON(w, r, json)
|
|
||||||
}
|
|
|
@ -1,8 +1,6 @@
|
||||||
package autocert
|
package autocert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/providers/dns/clouddns"
|
"github.com/go-acme/lego/v4/providers/dns/clouddns"
|
||||||
"github.com/go-acme/lego/v4/providers/dns/cloudflare"
|
"github.com/go-acme/lego/v4/providers/dns/cloudflare"
|
||||||
"github.com/go-acme/lego/v4/providers/dns/duckdns"
|
"github.com/go-acme/lego/v4/providers/dns/duckdns"
|
||||||
|
@ -31,7 +29,3 @@ var providersGenMap = map[string]ProviderGenerator{
|
||||||
ProviderDuckdns: providerGenerator(duckdns.NewDefaultConfig, duckdns.NewDNSProviderConfig),
|
ProviderDuckdns: providerGenerator(duckdns.NewDefaultConfig, duckdns.NewDNSProviderConfig),
|
||||||
ProviderOVH: providerGenerator(ovh.NewDefaultConfig, ovh.NewDNSProviderConfig),
|
ProviderOVH: providerGenerator(ovh.NewDefaultConfig, ovh.NewDNSProviderConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ErrGetCertFailure = errors.New("get certificate failed")
|
|
||||||
)
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package autocert
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -35,6 +36,8 @@ type (
|
||||||
CertExpiries map[string]time.Time
|
CertExpiries map[string]time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrGetCertFailure = errors.New("get certificate failed")
|
||||||
|
|
||||||
func (p *Provider) GetCert(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
func (p *Provider) GetCert(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||||
if p.tlsCert == nil {
|
if p.tlsCert == nil {
|
||||||
return nil, ErrGetCertFailure
|
return nil, ErrGetCertFailure
|
||||||
|
@ -248,10 +251,7 @@ func (p *Provider) renewIfNeeded() E.Error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.ObtainCert(); err != nil {
|
return p.ObtainCert()
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCertExpiries(cert *tls.Certificate) (CertExpiries, error) {
|
func getCertExpiries(cert *tls.Certificate) (CertExpiries, error) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ const (
|
||||||
CommandDebugListEntries = "debug-ls-entries"
|
CommandDebugListEntries = "debug-ls-entries"
|
||||||
CommandDebugListProviders = "debug-ls-providers"
|
CommandDebugListProviders = "debug-ls-providers"
|
||||||
CommandDebugListMTrace = "debug-ls-mtrace"
|
CommandDebugListMTrace = "debug-ls-mtrace"
|
||||||
CommandDebugListTasks = "debug-ls-tasks"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ValidCommands = []string{
|
var ValidCommands = []string{
|
||||||
|
@ -35,7 +34,6 @@ var ValidCommands = []string{
|
||||||
CommandDebugListEntries,
|
CommandDebugListEntries,
|
||||||
CommandDebugListProviders,
|
CommandDebugListProviders,
|
||||||
CommandDebugListMTrace,
|
CommandDebugListMTrace,
|
||||||
CommandDebugListTasks,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArgs() Args {
|
func GetArgs() Args {
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package error
|
package error
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidErrorJson = errors.New("invalid error json")
|
|
||||||
|
|
||||||
func newError(message string) error {
|
func newError(message string) error {
|
||||||
return errStr(message)
|
return errStr(message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
type StreamRoute struct {
|
type StreamRoute struct {
|
||||||
*entry.StreamEntry
|
*entry.StreamEntry
|
||||||
|
|
||||||
stream net.Stream `json:"-"`
|
stream net.Stream
|
||||||
|
|
||||||
HealthMon health.HealthMonitor `json:"health"`
|
HealthMon health.HealthMonitor `json:"health"`
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package health
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
|
||||||
)
|
|
||||||
|
|
||||||
var logger = logging.With().Str("module", "health_mon").Logger()
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/notif"
|
"github.com/yusing/go-proxy/internal/notif"
|
||||||
"github.com/yusing/go-proxy/internal/task"
|
"github.com/yusing/go-proxy/internal/task"
|
||||||
U "github.com/yusing/go-proxy/internal/utils"
|
U "github.com/yusing/go-proxy/internal/utils"
|
||||||
F "github.com/yusing/go-proxy/internal/utils/functional"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -31,11 +30,7 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var monMap = F.NewMapOf[string, HealthMonitor]()
|
var ErrNegativeInterval = errors.New("negative interval")
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNegativeInterval = errors.New("negative interval")
|
|
||||||
)
|
|
||||||
|
|
||||||
func newMonitor(url types.URL, config *HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
func newMonitor(url types.URL, config *HealthCheckConfig, healthCheckFunc HealthCheckFunc) *monitor {
|
||||||
mon := &monitor{
|
mon := &monitor{
|
||||||
|
@ -49,16 +44,11 @@ func newMonitor(url types.URL, config *HealthCheckConfig, healthCheckFunc Health
|
||||||
return mon
|
return mon
|
||||||
}
|
}
|
||||||
|
|
||||||
func Inspect(service string) (HealthMonitor, bool) {
|
|
||||||
return monMap.Load(service)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mon *monitor) ContextWithTimeout(cause string) (ctx context.Context, cancel context.CancelFunc) {
|
func (mon *monitor) ContextWithTimeout(cause string) (ctx context.Context, cancel context.CancelFunc) {
|
||||||
if mon.task != nil {
|
if mon.task != nil {
|
||||||
return context.WithTimeoutCause(mon.task.Context(), mon.config.Timeout, errors.New(cause))
|
return context.WithTimeoutCause(mon.task.Context(), mon.config.Timeout, errors.New(cause))
|
||||||
} else {
|
|
||||||
return context.WithTimeoutCause(context.Background(), mon.config.Timeout, errors.New(cause))
|
|
||||||
}
|
}
|
||||||
|
return context.WithTimeoutCause(context.Background(), mon.config.Timeout, errors.New(cause))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start implements task.TaskStarter.
|
// Start implements task.TaskStarter.
|
||||||
|
@ -85,9 +75,6 @@ func (mon *monitor) Start(routeSubtask task.Task) E.Error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
monMap.Store(mon.service, mon)
|
|
||||||
defer monMap.Delete(mon.service)
|
|
||||||
|
|
||||||
ticker := time.NewTicker(mon.config.Interval)
|
ticker := time.NewTicker(mon.config.Interval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue