feat: add an interface for handling http methods to be handled abstractly and implement the basic upload endpoint
This commit is contained in:
parent
3d41119f74
commit
38e330e02b
|
@ -2,6 +2,7 @@ package interfaces
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"go.sia.tech/jape"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockgen -source=http.go -destination=../mocks/interfaces/http.go -package=interfaces
|
//go:generate mockgen -source=http.go -destination=../mocks/interfaces/http.go -package=interfaces
|
||||||
|
@ -10,3 +11,7 @@ type HTTPService interface {
|
||||||
Service
|
Service
|
||||||
GetHandler() *httprouter.Router
|
GetHandler() *httprouter.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HTTPHandler interface {
|
||||||
|
SmallFileUpload(context *jape.Context)
|
||||||
|
}
|
||||||
|
|
|
@ -14,17 +14,22 @@ import (
|
||||||
var _ interfaces.HTTPService = (*HTTPImpl)(nil)
|
var _ interfaces.HTTPService = (*HTTPImpl)(nil)
|
||||||
|
|
||||||
type HTTPImpl struct {
|
type HTTPImpl struct {
|
||||||
node interfaces.Node
|
node interfaces.Node
|
||||||
|
handler interfaces.HTTPHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTP(node interfaces.Node) *HTTPImpl {
|
func NewHTTP(node interfaces.Node, handler interfaces.HTTPHandler) interfaces.HTTPService {
|
||||||
return &HTTPImpl{node: node}
|
return &HTTPImpl{
|
||||||
|
node: node,
|
||||||
|
handler: handler,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HTTPImpl) GetHandler() *httprouter.Router {
|
func (h *HTTPImpl) GetHandler() *httprouter.Router {
|
||||||
mux := jape.Mux(map[string]jape.Handler{
|
mux := jape.Mux(map[string]jape.Handler{
|
||||||
"GET /s5/version": h.versionHandler,
|
"GET /s5/version": h.versionHandler,
|
||||||
"GET /s5/p2p": h.p2pHandler,
|
"GET /s5/p2p": h.p2pHandler,
|
||||||
|
"POST /s5/upload": h.uploadHandler,
|
||||||
})
|
})
|
||||||
|
|
||||||
return mux
|
return mux
|
||||||
|
@ -80,3 +85,7 @@ func (h *HTTPImpl) p2pHandler(ctx jape.Context) {
|
||||||
h.node.ConnectionTracker().Done()
|
h.node.ConnectionTracker().Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HTTPImpl) uploadHandler(context jape.Context) {
|
||||||
|
h.handler.SmallFileUpload(&context)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue