Categorygithub.com/cention-sany/api2go
modulepackage
0.0.0-20201008010558-077e2b51cff2
Repository: https://github.com/cention-sany/api2go.git
Documentation: pkg.go.dev

# README

api2go

GoDoc Build Status

Forked from project api2go.

Features

  • Most of the features in original project api2go.
  • Gin is the main framework and google/jsonapi marshaler and unmarshaler tool.
  • Original project supports Gin framework as adapter which do not work well with Gin middlewares especially the Gin RouterGroup.

# Packages

Package examples shows how to implement a basic CRUD for two data structures with the api2go server functionality.

# Functions

NewAPIWithResolver can be used to create an API with a custom URL resolver.
NewCallbackResolver handles each resolve via your provided callback func.
No description provided by the author
No description provided by the author
NewHTTPError creates a new error with message and status code.
No description provided by the author
NewStaticResolver returns a simple resolver that will always answer with the same url.
OffsetPage is helper to check if r contains pagination query or not and turn it into SQL friendly offset and limit value.

# Variables

EmptyObject only apply to top level object which return empty json array [] when the doc can not be found but the requested path is legitimate.
EmptyObject only apply to top level object which return null when the doc can not be found but the requested path is legitimate.

# Structs

API is a REST JSONAPI.
DefaultLinks is helper struct to generate link object for Responder or any struct that embeds it.
Doc implements noder and MarshalJSON.
HTTPError is used for errors.
Pagination represents information needed to return pagination links.
RelationNode implements noder and MarshalJSON.
Request contains additional information for FindOne and Find Requests.
The Response struct implements api2go.Responder and can be used as a default implementation for your responses you can fill the field `Meta` with all the metadata your application needs like license, tokens, etc.

# Interfaces

APIContexter embedding context.Context and requesting two helper functions.
The CRUD interface MUST be implemented in order to use the api2go api.
The EditToManyRelations interface can be optionally implemented to add and delete to-many relationships on a already unmarshalled struct.
The FindAll interface can be optionally implemented to fetch all records at once.
The Identifier interface is necessary to give an element a unique ID.
The LinksResponder interface may be used when the response object is able to return a set of links for the top-level response object.
No description provided by the author
The ObjectInitializer interface can be implemented to have the ability to change a created object before Unmarshal is called.
The PaginatedFindAll interface can be optionally implemented to fetch a subset of all records.
RequestAwareURLResolver allows you to dynamically change generated urls.
The Responder interface is used by all Resource Methods as a container for the Response.
The UnmarshalIdentifier interface must be implemented to set the ID during unmarshalling.
The UnmarshalToManyRelations interface must be implemented to unmarshal to-many relations.
The UnmarshalToOneRelations interface must be implemented to unmarshal to-one relations.
URLResolver allows you to implement a static way to return a baseURL for all incoming requests for one api2go instance.