Files

779 lines
26 KiB
Go

//go:build go1.22
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.
package api
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/oapi-codegen/runtime"
)
const (
HttpAuthScopes = "HttpAuth.Scopes"
)
// AggregateRequestBody defines model for AggregateRequestBody.
type AggregateRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Pipeline An array of aggregation stages.
Pipeline *json.RawMessage `json:"pipeline,omitempty"`
}
// AggregateResponseBody defines model for AggregateResponseBody.
type AggregateResponseBody struct {
// Documents An array that contains the result set of the aggregation.
Documents json.RawMessage `json:"documents"`
}
// DeleteRequestBody defines model for DeleteRequestBody.
type DeleteRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Filter A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see [Query Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#query-operators).
Filter *json.RawMessage `json:"filter,omitempty"`
}
// DeleteResponseBody defines model for DeleteResponseBody.
type DeleteResponseBody struct {
// DeletedCount The number of documents that were deleted.
DeletedCount interface{} `json:"deletedCount"`
}
// Error defines model for Error.
type Error struct {
// Error A message that describes the error.
Error string `json:"error,omitempty"`
// ErrorCode The error type.
ErrorCode string `json:"error_code,omitempty"`
// Link A link to a [log entry](https://www.mongodb.com/docs/atlas/app-services/logs/endpoint/) for the failed operation.
Link string `json:"link,omitempty"`
}
// ErrorMissingAuthenticationParameter defines model for ErrorMissingAuthenticationParameter.
type ErrorMissingAuthenticationParameter struct {
Error interface{} `json:"error,omitempty"`
ErrorCode interface{} `json:"error_code,omitempty"`
// Link A link to a [log entry](https://www.mongodb.com/docs/atlas/app-services/logs/endpoint/) for the failed operation.
Link string `json:"link,omitempty"`
}
// ErrorNoAuthenticationSpecified defines model for ErrorNoAuthenticationSpecified.
type ErrorNoAuthenticationSpecified struct {
Error interface{} `json:"error,omitempty"`
ErrorCode interface{} `json:"error_code,omitempty"`
// Link A link to a [log entry](https://www.mongodb.com/docs/atlas/app-services/logs/endpoint/) for the failed operation.
Link string `json:"link,omitempty"`
}
// ErrorUserNotFound defines model for ErrorUserNotFound.
type ErrorUserNotFound struct {
Error interface{} `json:"error,omitempty"`
ErrorCode interface{} `json:"error_code,omitempty"`
// Link A link to a [log entry](https://www.mongodb.com/docs/atlas/app-services/logs/endpoint/) for the failed operation.
Link string `json:"link,omitempty"`
}
// Filter defines model for Filter.
type Filter struct {
// Filter A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see [Query Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#query-operators).
Filter *json.RawMessage `json:"filter,omitempty"`
}
// FindManyRequestBody defines model for FindManyRequestBody.
type FindManyRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Filter A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see [Query Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#query-operators).
Filter *json.RawMessage `json:"filter,omitempty"`
// Limit The maximum number of matching documents to include the in the response.
Limit *float32 `json:"limit,omitempty"`
// Projection A [MongoDB projection](https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/) for matched documents returned by the operation.
Projection *json.RawMessage `json:"projection,omitempty"`
// Skip The number of matching documents to omit from the response.
Skip *float32 `json:"skip,omitempty"`
// Sort A [MongoDB sort expression](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/) that indicates sorted field names and directions.
Sort *json.RawMessage `json:"sort,omitempty"`
}
// FindManyResponseBody The result of a find operation.
type FindManyResponseBody struct {
// Documents A list of documents that match the specified filter.
Documents *json.RawMessage `json:"documents,omitempty"`
}
// FindOneRequestBody defines model for FindOneRequestBody.
type FindOneRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Filter A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see [Query Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#query-operators).
Filter *json.RawMessage `json:"filter,omitempty"`
// Projection A [MongoDB projection](https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/) for matched documents returned by the operation.
Projection *json.RawMessage `json:"projection,omitempty"`
}
// FindOneResponseBody The result of a findOne operation.
type FindOneResponseBody struct {
// Document A document that matches the specified filter. If no documents match, this is `null`.
Document *json.RawMessage `json:"document"`
}
// InsertManyRequestBody defines model for InsertManyRequestBody.
type InsertManyRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Documents A list of documents to insert into the collection.
Documents json.RawMessage `json:"documents"`
}
// InsertManyResponseBody The result of an insertMany operation.
type InsertManyResponseBody struct {
// InsertedIds A list of the `_id` values of the inserted documents.
InsertedIds *[]any `json:"insertedIds,omitempty"`
}
// InsertOneRequestBody defines model for InsertOneRequestBody.
type InsertOneRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Document A document to insert into the collection.
Document json.RawMessage `json:"document"`
}
// InsertOneResponseBody The result of an insertOne operation.
type InsertOneResponseBody struct {
// InsertedId The `_id` value of the inserted document.
InsertedId *any `json:"insertedId,omitempty"`
}
// Limit defines model for Limit.
type Limit struct {
// Limit The maximum number of matching documents to include the in the response.
Limit *float32 `json:"limit,omitempty"`
}
// Namespace defines model for Namespace.
type Namespace struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
}
// Projection defines model for Projection.
type Projection struct {
// Projection A [MongoDB projection](https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/) for matched documents returned by the operation.
Projection *json.RawMessage `json:"projection,omitempty"`
}
// Skip defines model for Skip.
type Skip struct {
// Skip The number of matching documents to omit from the response.
Skip *float32 `json:"skip,omitempty"`
}
// Sort defines model for Sort.
type Sort struct {
// Sort A [MongoDB sort expression](https://www.mongodb.com/docs/manual/reference/method/cursor.sort/) that indicates sorted field names and directions.
Sort *json.RawMessage `json:"sort,omitempty"`
}
// UpdateRequestBody defines model for UpdateRequestBody.
type UpdateRequestBody struct {
// Collection The name of a collection in the specified database.
Collection string `json:"collection"`
// DataSource The name of a linked MongoDB Atlas data source. This is
// commonly `"mongodb-atlas"` though it may be different in
// your App if you chose a different name when you created the
// data source.
DataSource string `json:"dataSource"`
// Database The name of a database in the specified data source.
Database string `json:"database"`
// Filter A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see [Query Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#query-operators).
Filter json.RawMessage `json:"filter"`
// Update A MongoDB update expression to apply to matching documents. For a list of all update operators that the Data API supports, see [Update Operators](https://www.mongodb.com/docs/atlas/app-services/mongodb/crud-and-aggregation-apis/#update-operators).
Update json.RawMessage `json:"update"`
// Upsert When `true`, if the update filter does not match any
// existing documents, then insert a new document based on
// the filter and the specified update operation.
Upsert *bool `json:"upsert,omitempty"`
}
// UpdateResponseBody defines model for UpdateResponseBody.
type UpdateResponseBody struct {
// MatchedCount The number of documents matched by the query filter.
MatchedCount interface{} `json:"matchedCount"`
// ModifiedCount The number of matched documents that were modified.
ModifiedCount interface{} `json:"modifiedCount"`
// UpsertedId The `_id` value of the upserted document.
UpsertedId *string `json:"upsertedId,omitempty"`
}
// BadRequestError defines model for BadRequestError.
type BadRequestError struct {
union json.RawMessage
}
// UnauthorizedRequestError Indicates that no user matched the provided authentication
// credentials.
type UnauthorizedRequestError = ErrorUserNotFound
// AggregateJSONBody defines parameters for Aggregate.
type AggregateJSONBody = AggregateRequestBody
// DeleteManyJSONBody defines parameters for DeleteMany.
type DeleteManyJSONBody = DeleteRequestBody
// DeleteOneJSONBody defines parameters for DeleteOne.
type DeleteOneJSONBody = DeleteRequestBody
// FindJSONBody defines parameters for Find.
type FindJSONBody = FindManyRequestBody
// FindOneJSONBody defines parameters for FindOne.
type FindOneJSONBody = FindOneRequestBody
// InsertManyJSONBody defines parameters for InsertMany.
type InsertManyJSONBody = InsertManyRequestBody
// InsertOneJSONBody defines parameters for InsertOne.
type InsertOneJSONBody = InsertOneRequestBody
// UpdateManyJSONBody defines parameters for UpdateMany.
type UpdateManyJSONBody = UpdateRequestBody
// UpdateOneJSONBody defines parameters for UpdateOne.
type UpdateOneJSONBody = UpdateRequestBody
// AggregateJSONRequestBody defines body for Aggregate for application/json ContentType.
type AggregateJSONRequestBody = AggregateJSONBody
// DeleteManyJSONRequestBody defines body for DeleteMany for application/json ContentType.
type DeleteManyJSONRequestBody = DeleteManyJSONBody
// DeleteOneJSONRequestBody defines body for DeleteOne for application/json ContentType.
type DeleteOneJSONRequestBody = DeleteOneJSONBody
// FindJSONRequestBody defines body for Find for application/json ContentType.
type FindJSONRequestBody = FindJSONBody
// FindOneJSONRequestBody defines body for FindOne for application/json ContentType.
type FindOneJSONRequestBody = FindOneJSONBody
// InsertManyJSONRequestBody defines body for InsertMany for application/json ContentType.
type InsertManyJSONRequestBody = InsertManyJSONBody
// InsertOneJSONRequestBody defines body for InsertOne for application/json ContentType.
type InsertOneJSONRequestBody = InsertOneJSONBody
// UpdateManyJSONRequestBody defines body for UpdateMany for application/json ContentType.
type UpdateManyJSONRequestBody = UpdateManyJSONBody
// UpdateOneJSONRequestBody defines body for UpdateOne for application/json ContentType.
type UpdateOneJSONRequestBody = UpdateOneJSONBody
// AsErrorNoAuthenticationSpecified returns the union data inside the BadRequestError as a ErrorNoAuthenticationSpecified
func (t BadRequestError) AsErrorNoAuthenticationSpecified() (ErrorNoAuthenticationSpecified, error) {
var body ErrorNoAuthenticationSpecified
err := json.Unmarshal(t.union, &body)
return body, err
}
// FromErrorNoAuthenticationSpecified overwrites any union data inside the BadRequestError as the provided ErrorNoAuthenticationSpecified
func (t *BadRequestError) FromErrorNoAuthenticationSpecified(v ErrorNoAuthenticationSpecified) error {
b, err := json.Marshal(v)
t.union = b
return err
}
// MergeErrorNoAuthenticationSpecified performs a merge with any union data inside the BadRequestError, using the provided ErrorNoAuthenticationSpecified
func (t *BadRequestError) MergeErrorNoAuthenticationSpecified(v ErrorNoAuthenticationSpecified) error {
b, err := json.Marshal(v)
if err != nil {
return err
}
merged, err := runtime.JSONMerge(t.union, b)
t.union = merged
return err
}
// AsErrorMissingAuthenticationParameter returns the union data inside the BadRequestError as a ErrorMissingAuthenticationParameter
func (t BadRequestError) AsErrorMissingAuthenticationParameter() (ErrorMissingAuthenticationParameter, error) {
var body ErrorMissingAuthenticationParameter
err := json.Unmarshal(t.union, &body)
return body, err
}
// FromErrorMissingAuthenticationParameter overwrites any union data inside the BadRequestError as the provided ErrorMissingAuthenticationParameter
func (t *BadRequestError) FromErrorMissingAuthenticationParameter(v ErrorMissingAuthenticationParameter) error {
b, err := json.Marshal(v)
t.union = b
return err
}
// MergeErrorMissingAuthenticationParameter performs a merge with any union data inside the BadRequestError, using the provided ErrorMissingAuthenticationParameter
func (t *BadRequestError) MergeErrorMissingAuthenticationParameter(v ErrorMissingAuthenticationParameter) error {
b, err := json.Marshal(v)
if err != nil {
return err
}
merged, err := runtime.JSONMerge(t.union, b)
t.union = merged
return err
}
func (t BadRequestError) MarshalJSON() ([]byte, error) {
b, err := t.union.MarshalJSON()
return b, err
}
func (t *BadRequestError) UnmarshalJSON(b []byte) error {
err := t.union.UnmarshalJSON(b)
return err
}
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Aggregate Documents
// (POST /action/aggregate)
Aggregate(w http.ResponseWriter, r *http.Request)
// Delete Documents
// (POST /action/deleteMany)
DeleteMany(w http.ResponseWriter, r *http.Request)
// Delete One Document
// (POST /action/deleteOne)
DeleteOne(w http.ResponseWriter, r *http.Request)
// Find Documents
// (POST /action/find)
Find(w http.ResponseWriter, r *http.Request)
// Find One Document
// (POST /action/findOne)
FindOne(w http.ResponseWriter, r *http.Request)
// Insert Documents
// (POST /action/insertMany)
InsertMany(w http.ResponseWriter, r *http.Request)
// Insert One Document
// (POST /action/insertOne)
InsertOne(w http.ResponseWriter, r *http.Request)
// Update Documents
// (POST /action/updateMany)
UpdateMany(w http.ResponseWriter, r *http.Request)
// Update One Document
// (POST /action/updateOne)
UpdateOne(w http.ResponseWriter, r *http.Request)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
type MiddlewareFunc func(http.Handler) http.Handler
// Aggregate operation middleware
func (siw *ServerInterfaceWrapper) Aggregate(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.Aggregate(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// DeleteMany operation middleware
func (siw *ServerInterfaceWrapper) DeleteMany(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.DeleteMany(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// DeleteOne operation middleware
func (siw *ServerInterfaceWrapper) DeleteOne(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.DeleteOne(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// Find operation middleware
func (siw *ServerInterfaceWrapper) Find(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.Find(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// FindOne operation middleware
func (siw *ServerInterfaceWrapper) FindOne(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.FindOne(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// InsertMany operation middleware
func (siw *ServerInterfaceWrapper) InsertMany(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.InsertMany(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// InsertOne operation middleware
func (siw *ServerInterfaceWrapper) InsertOne(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.InsertOne(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// UpdateMany operation middleware
func (siw *ServerInterfaceWrapper) UpdateMany(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.UpdateMany(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// UpdateOne operation middleware
func (siw *ServerInterfaceWrapper) UpdateOne(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, HttpAuthScopes, []string{})
r = r.WithContext(ctx)
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.UpdateOne(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
type UnescapedCookieParamError struct {
ParamName string
Err error
}
func (e *UnescapedCookieParamError) Error() string {
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
}
func (e *UnescapedCookieParamError) Unwrap() error {
return e.Err
}
type UnmarshalingParamError struct {
ParamName string
Err error
}
func (e *UnmarshalingParamError) Error() string {
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}
func (e *UnmarshalingParamError) Unwrap() error {
return e.Err
}
type RequiredParamError struct {
ParamName string
}
func (e *RequiredParamError) Error() string {
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
}
type RequiredHeaderError struct {
ParamName string
Err error
}
func (e *RequiredHeaderError) Error() string {
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
}
func (e *RequiredHeaderError) Unwrap() error {
return e.Err
}
type InvalidParamFormatError struct {
ParamName string
Err error
}
func (e *InvalidParamFormatError) Error() string {
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
}
func (e *InvalidParamFormatError) Unwrap() error {
return e.Err
}
type TooManyValuesForParamError struct {
ParamName string
Count int
}
func (e *TooManyValuesForParamError) Error() string {
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{})
}
// ServeMux is an abstraction of http.ServeMux.
type ServeMux interface {
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
type StdHTTPServerOptions struct {
BaseURL string
BaseRouter ServeMux
Middlewares []MiddlewareFunc
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, m ServeMux) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseRouter: m,
})
}
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseURL: baseURL,
BaseRouter: m,
})
}
// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
m := options.BaseRouter
if m == nil {
m = http.NewServeMux()
}
if options.ErrorHandlerFunc == nil {
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
ErrorHandlerFunc: options.ErrorHandlerFunc,
}
m.HandleFunc("POST "+options.BaseURL+"/action/aggregate", wrapper.Aggregate)
m.HandleFunc("POST "+options.BaseURL+"/action/deleteMany", wrapper.DeleteMany)
m.HandleFunc("POST "+options.BaseURL+"/action/deleteOne", wrapper.DeleteOne)
m.HandleFunc("POST "+options.BaseURL+"/action/find", wrapper.Find)
m.HandleFunc("POST "+options.BaseURL+"/action/findOne", wrapper.FindOne)
m.HandleFunc("POST "+options.BaseURL+"/action/insertMany", wrapper.InsertMany)
m.HandleFunc("POST "+options.BaseURL+"/action/insertOne", wrapper.InsertOne)
m.HandleFunc("POST "+options.BaseURL+"/action/updateMany", wrapper.UpdateMany)
m.HandleFunc("POST "+options.BaseURL+"/action/updateOne", wrapper.UpdateOne)
return m
}