45233d939a
Using query request struct to query resources Signed-off-by: Lorenzo Fontana <lo@linux.com> Use query.ProxyRequest instead query.Request Signed-off-by: Lorenzo Fontana <lo@linux.com> Proxy request from idpd Signed-off-by: Lorenzo Fontana <lo@linux.com> Comments about the desired results Signed-off-by: Lorenzo Fontana <lo@linux.com> V1 endpoints working with flux Signed-off-by: Lorenzo Fontana <lo@linux.com> Influxql working for v1 Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> V2 influxql query endpoint working Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Signed-off-by: Lorenzo Fontana <lo@linux.com> V2 Flux compiler support Co-authored-by: Michael De Sa <mjdesa@gmail.com> Signed-off-by: Lorenzo Fontana <lo@linux.com> Improve comments in bolt sources and give error on self Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Review tests failing Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Avoid type casts for compiler types Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> Using nil instead of dbrp mapping service for influxql v1 Signed-off-by: Lorenzo Fontana <lo@linux.com> Check if compiler types are valid for influxql Signed-off-by: Lorenzo Fontana <lo@linux.com> Organization as query param in the flux external handler Signed-off-by: Lorenzo Fontana <lo@linux.com> feat(http): update swagger documentation for flux query endpoint feat(http): document query endpoint design The code documented does not currently work. It is indended that this will be implemented in follow up PRs. feat(platform): move source to platform package The source Query endpoint implements what's in the query swagger docs Signed-off-by: Lorenzo Fontana <lo@linux.com> Co-authored-by: Michael De Sa <mjdesa@gmail.com> feat(platform): allow for encoding and decoding of csv dialects feat(platform): specify dialect in flux page Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com> Co-authored-by: Michael Desa <mjdesa@gmail.com> |
||
---|---|---|
.. | ||
influxdb | ||
README.md | ||
assets.go | ||
auth_service.go | ||
bucket_service.go | ||
chronograf_handler.go | ||
client.go | ||
dashboard_service.go | ||
dashboard_test.go | ||
errors.go | ||
errors_test.go | ||
external_query_handler.go | ||
flux_lang.go | ||
handler.go | ||
org_service.go | ||
platform_handler.go | ||
proxy_query_service.go | ||
query_service.go | ||
server.go | ||
source_proxy_service.go | ||
source_service.go | ||
status.go | ||
swagger.yml | ||
task_service.go | ||
token_parse_test.go | ||
token_parser.go | ||
usage_service.go | ||
user_service.go | ||
view_service.go | ||
view_test.go |
README.md
HTTP Handler Style Guide
HTTP Handler
- Each handler should implement
http.Handler
- This can be done by embedding a
httprouter.Router
(a light weight HTTP router that supports variables in the routing pattern and matches against the request method)
- This can be done by embedding a
- Required services should be exported on the struct
// ThingHandler represents an HTTP API handler for things.
type ThingHandler struct {
// embedded httprouter.Router as a lazy way to implement http.Handler
*httprouter.Router
ThingService platform.ThingService
AuthorizationService platform.AuthorizationService
Logger *zap.Logger
}
HTTP Handler Constructor
- Routes should be declared in the constructor
// NewThingHandler returns a new instance of ThingHandler.
func NewThingHandler() *ThingHandler {
h := &ThingHandler{
Router: httprouter.New(),
Logger: zap.Nop(),
}
h.HandlerFunc("POST", "/v1/things", h.handlePostThing)
h.HandlerFunc("GET", "/v1/things", h.handleGetThings)
return h
}
Route handlers (http.HandlerFunc
s)
- Each route handler should have an associated request struct and decode function
- The decode function should take a
context.Context
and an*http.Request
and return the associated route request struct
type postThingRequest struct {
Thing *platform.Thing
}
func decodePostThingRequest(ctx context.Context, r *http.Request) (*postThingRequest, error) {
t := &platform.Thing{}
if err := json.NewDecoder(r.Body).Decode(t); err != nil {
return nil, err
}
return &postThingRequest{
Thing: t,
}, nil
}
- Route
http.HandlerFuncs
should separate the decoding and encoding of HTTP requests/response from actual handler logic
// handlePostThing is the HTTP handler for the POST /v1/things route.
func (h *ThingHandler) handlePostThing(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := decodePostThingRequest(ctx, r)
if err != nil {
errors.EncodeHTTP(ctx, err, w)
return
}
// Do stuff here
if err := h.ThingService.CreateThing(ctx, req.Thing); err != nil {
errors.EncodeHTTP(ctx, err, w)
return
}
if err := encodeResponse(ctx, w, http.StatusCreated, req.Thing); err != nil {
h.Logger.Info("encoding response failed", zap.Error(err))
return
}
}
http.HandlerFunc
's that require particular encoding of http responses should implement an encode response function