remove unused code

This commit is contained in:
yusing 2024-11-02 03:04:15 +08:00
parent 9889b5a8d3
commit 67b6e40f85
10 changed files with 8 additions and 78 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/yusing/go-proxy/internal/api/v1/auth"
. "github.com/yusing/go-proxy/internal/api/v1/utils"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/config"
)
type ServeMux struct{ *http.ServeMux }
@ -26,8 +25,6 @@ func NewHandler() http.Handler {
mux := NewServeMux()
mux.HandleFunc("GET", "/v1", v1.Index)
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("GET", "/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)
}
}
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)
}
}

View file

@ -32,8 +32,6 @@ var (
const tokenExpiration = 24 * time.Hour
const jwtClaimKeyUsername = "username"
func validatePassword(cred *Credentials) error {
if cred.Username != common.APIUser {
return ErrInvalidUsername.Subject(cred.Username)
@ -114,7 +112,7 @@ func checkToken(w http.ResponseWriter, r *http.Request) (ok bool) {
var claims Claims
token, err := jwt.ParseWithClaims(tokenCookie.Value, &claims, func(t *jwt.Token) (interface{}, error) {
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
})

View file

@ -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)
}

View file

@ -1,8 +1,6 @@
package autocert
import (
"errors"
"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/duckdns"
@ -31,7 +29,3 @@ var providersGenMap = map[string]ProviderGenerator{
ProviderDuckdns: providerGenerator(duckdns.NewDefaultConfig, duckdns.NewDNSProviderConfig),
ProviderOVH: providerGenerator(ovh.NewDefaultConfig, ovh.NewDNSProviderConfig),
}
var (
ErrGetCertFailure = errors.New("get certificate failed")
)

View file

@ -3,6 +3,7 @@ package autocert
import (
"crypto/tls"
"crypto/x509"
"errors"
"os"
"path"
"reflect"
@ -35,6 +36,8 @@ type (
CertExpiries map[string]time.Time
)
var ErrGetCertFailure = errors.New("get certificate failed")
func (p *Provider) GetCert(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
if p.tlsCert == nil {
return nil, ErrGetCertFailure
@ -248,10 +251,7 @@ func (p *Provider) renewIfNeeded() E.Error {
return nil
}
if err := p.ObtainCert(); err != nil {
return err
}
return nil
return p.ObtainCert()
}
func getCertExpiries(cert *tls.Certificate) (CertExpiries, error) {

View file

@ -21,7 +21,6 @@ const (
CommandDebugListEntries = "debug-ls-entries"
CommandDebugListProviders = "debug-ls-providers"
CommandDebugListMTrace = "debug-ls-mtrace"
CommandDebugListTasks = "debug-ls-tasks"
)
var ValidCommands = []string{
@ -35,7 +34,6 @@ var ValidCommands = []string{
CommandDebugListEntries,
CommandDebugListProviders,
CommandDebugListMTrace,
CommandDebugListTasks,
}
func GetArgs() Args {

View file

@ -1,12 +1,9 @@
package error
import (
"errors"
"fmt"
)
var ErrInvalidErrorJson = errors.New("invalid error json")
func newError(message string) error {
return errStr(message)
}

View file

@ -19,7 +19,7 @@ import (
type StreamRoute struct {
*entry.StreamEntry
stream net.Stream `json:"-"`
stream net.Stream
HealthMon health.HealthMonitor `json:"health"`

View file

@ -1,7 +0,0 @@
package health
import (
"github.com/yusing/go-proxy/internal/logging"
)
var logger = logging.With().Str("module", "health_mon").Logger()

View file

@ -13,7 +13,6 @@ import (
"github.com/yusing/go-proxy/internal/notif"
"github.com/yusing/go-proxy/internal/task"
U "github.com/yusing/go-proxy/internal/utils"
F "github.com/yusing/go-proxy/internal/utils/functional"
)
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 {
mon := &monitor{
@ -49,16 +44,11 @@ func newMonitor(url types.URL, config *HealthCheckConfig, healthCheckFunc Health
return mon
}
func Inspect(service string) (HealthMonitor, bool) {
return monMap.Load(service)
}
func (mon *monitor) ContextWithTimeout(cause string) (ctx context.Context, cancel context.CancelFunc) {
if mon.task != nil {
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.
@ -85,9 +75,6 @@ func (mon *monitor) Start(routeSubtask task.Task) E.Error {
return
}
monMap.Store(mon.service, mon)
defer monMap.Delete(mon.service)
ticker := time.NewTicker(mon.config.Interval)
defer ticker.Stop()