60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
|
|
package api
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/go-chi/chi/v5"
|
||
|
|
)
|
||
|
|
|
||
|
|
type PatchImpl interface {
|
||
|
|
Summary(*PatchSummaryReq) (*PatchSummaryResp, error)
|
||
|
|
View(*PatchViewReq) (*PatchViewResp, error)
|
||
|
|
|
||
|
|
List(*PatchListReq) (*PatchListResp, error)
|
||
|
|
ListPrefix(*PatchListPrefixReq) (*PatchListPrefixResp, error)
|
||
|
|
|
||
|
|
Status() *PingResp
|
||
|
|
}
|
||
|
|
|
||
|
|
type PatchSummaryReq struct{}
|
||
|
|
type PatchSummaryResp struct{}
|
||
|
|
type PatchViewReq struct{}
|
||
|
|
type PatchViewResp struct{}
|
||
|
|
|
||
|
|
type PatchSummaryBatchReq struct{}
|
||
|
|
type PatchSummaryBatchResp struct{}
|
||
|
|
|
||
|
|
type PatchListReq struct{}
|
||
|
|
type PatchListResp struct{}
|
||
|
|
|
||
|
|
type PatchListPrefixReq struct{}
|
||
|
|
type PatchListPrefixResp struct{}
|
||
|
|
|
||
|
|
func (a *ApiHandler) RoutePatch(r chi.Router) {
|
||
|
|
//search
|
||
|
|
r.Get("/file/{packagename}/{version}", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
req := &PatchSummaryReq{}
|
||
|
|
returnJson(w, req, a.patch.Summary)
|
||
|
|
})
|
||
|
|
r.Get("/file/{packagename}/{version}/*", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
req := &PatchViewReq{}
|
||
|
|
returnJson(w, req, a.patch.View)
|
||
|
|
})
|
||
|
|
|
||
|
|
//list
|
||
|
|
r.Get("/list", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
req := &PatchListReq{}
|
||
|
|
returnJson(w, req, a.patch.List)
|
||
|
|
})
|
||
|
|
r.Get("/prefix/{prefix}", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
req := &PatchListPrefixReq{}
|
||
|
|
returnJson(w, req, a.patch.ListPrefix)
|
||
|
|
})
|
||
|
|
|
||
|
|
// status
|
||
|
|
r.Get("/ping", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
json.NewEncoder(w).Encode(a.patch.Status())
|
||
|
|
})
|
||
|
|
}
|