pht: self-defined path
This commit is contained in:
parent
b7dd9dea3f
commit
24971091e3
@ -76,9 +76,9 @@ func (l *phtListener) Init(md md.Metadata) (err error) {
|
|||||||
l.addr = ln.Addr()
|
l.addr = ln.Addr()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/authorize", l.handleAuthorize)
|
mux.HandleFunc(l.md.authorizePath, l.handleAuthorize)
|
||||||
mux.HandleFunc("/push", l.handlePush)
|
mux.HandleFunc(l.md.pushPath, l.handlePush)
|
||||||
mux.HandleFunc("/pull", l.handlePull)
|
mux.HandleFunc(l.md.pullPath, l.handlePull)
|
||||||
|
|
||||||
l.server = &http.Server{
|
l.server = &http.Server{
|
||||||
Addr: l.options.Addr,
|
Addr: l.options.Addr,
|
||||||
|
@ -1,29 +1,51 @@
|
|||||||
package pht
|
package pht
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
mdata "github.com/go-gost/gost/pkg/metadata"
|
mdata "github.com/go-gost/gost/pkg/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
defaultAuthorizePath = "/authorize"
|
||||||
|
defaultPushPath = "/push"
|
||||||
|
defaultPullPath = "/pull"
|
||||||
defaultBacklog = 128
|
defaultBacklog = 128
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
path string
|
authorizePath string
|
||||||
|
pushPath string
|
||||||
|
pullPath string
|
||||||
backlog int
|
backlog int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *phtListener) parseMetadata(md mdata.Metadata) (err error) {
|
func (l *phtListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
const (
|
const (
|
||||||
path = "path"
|
authorizePath = "authorizePath"
|
||||||
|
pushPath = "pushPath"
|
||||||
|
pullPath = "pullPath"
|
||||||
|
|
||||||
backlog = "backlog"
|
backlog = "backlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
l.md.authorizePath = mdata.GetString(md, authorizePath)
|
||||||
|
if !strings.HasPrefix(l.md.authorizePath, "/") {
|
||||||
|
l.md.authorizePath = defaultAuthorizePath
|
||||||
|
}
|
||||||
|
l.md.pushPath = mdata.GetString(md, pushPath)
|
||||||
|
if !strings.HasPrefix(l.md.pushPath, "/") {
|
||||||
|
l.md.pushPath = defaultPushPath
|
||||||
|
}
|
||||||
|
l.md.pullPath = mdata.GetString(md, pullPath)
|
||||||
|
if !strings.HasPrefix(l.md.pullPath, "/") {
|
||||||
|
l.md.pullPath = defaultPullPath
|
||||||
|
}
|
||||||
|
|
||||||
l.md.backlog = mdata.GetInt(md, backlog)
|
l.md.backlog = mdata.GetInt(md, backlog)
|
||||||
if l.md.backlog <= 0 {
|
if l.md.backlog <= 0 {
|
||||||
l.md.backlog = defaultBacklog
|
l.md.backlog = defaultBacklog
|
||||||
}
|
}
|
||||||
|
|
||||||
l.md.path = mdata.GetString(md, path)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user