mirror of
https://github.com/micromdm/micromdm/
synced 2026-06-19 10:35:45 +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 user
|
|
|
|
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 {
|
|
ApplyUserEndpoint endpoint.Endpoint
|
|
ListUsersEndpoint endpoint.Endpoint
|
|
}
|
|
|
|
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
|
return Endpoints{
|
|
ApplyUserEndpoint: endpoint.Chain(outer, others...)(MakeApplyUserEndpoint(s)),
|
|
ListUsersEndpoint: endpoint.Chain(outer, others...)(MakeListUsersEndpoint(s)),
|
|
}
|
|
}
|
|
|
|
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
|
// PUT /v1/users create or replace an user
|
|
// GET /v1/users get a list of users managed by the server
|
|
|
|
r.Methods("PUT").Path("/v1/users").Handler(httptransport.NewServer(
|
|
e.ApplyUserEndpoint,
|
|
decodeApplyUserRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
|
|
r.Methods("GET").Path("/v1/users").Handler(httptransport.NewServer(
|
|
e.ListUsersEndpoint,
|
|
decodeListUsersRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
}
|