mirror of
https://github.com/micromdm/micromdm/
synced 2026-07-02 00:15:41 +08:00
Simplified the registration of HTTP routes. Moved basic auth middleware to use the provided go-kit library.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package appstore
|
|
|
|
import (
|
|
"github.com/go-kit/kit/endpoint"
|
|
httptransport "github.com/go-kit/kit/transport/http"
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/micromdm/micromdm/pkg/httputil"
|
|
)
|
|
|
|
type Endpoints struct {
|
|
AppUploadEndpoint endpoint.Endpoint
|
|
ListAppsEndpoint endpoint.Endpoint
|
|
}
|
|
|
|
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
|
return Endpoints{
|
|
AppUploadEndpoint: endpoint.Chain(outer, others...)(MakeUploadAppEndpiont(s)),
|
|
ListAppsEndpoint: endpoint.Chain(outer, others...)(MakeListAppsEndpoint(s)),
|
|
}
|
|
}
|
|
|
|
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
|
// POST /v1/apps upload an app to the server
|
|
// GET /v1/apps list apps managed by the server
|
|
|
|
r.Methods("POST").Path("/v1/apps").Handler(httptransport.NewServer(
|
|
e.AppUploadEndpoint,
|
|
decodeAppUploadRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
|
|
r.Methods("GET").Path("/v1/apps").Handler(httptransport.NewServer(
|
|
e.ListAppsEndpoint,
|
|
decodeListAppsRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
}
|