api

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonapiCustomError

func JsonapiCustomError(statusCode int, status, source, title, detail *string) (int, interface{})

JsonapiCustomError single error

func JsonapiErrorResp

func JsonapiErrorResp(status int, msg string) (int, interface{})

JsonapiErrorResp single error json api body

func JsonapiErrorsResp

func JsonapiErrorsResp(status int, msges ...string) (int, interface{})

JsonapiErrorsResp multiple error json api body

func JsonapiResourceResp

func JsonapiResourceResp(status int, resType, resID string, attr interface{}) (int, interface{})

JsonapiResourceResp a generic jsonapi resource response with "type" and "id"

func JsonapiResourcesResp

func JsonapiResourcesResp(status int, resType, resID string, metaData interface{}, attrs ...interface{}) (int, interface{})

JsonapiResourcesResp a generic jsonapi multiple resource response with "type" and "id"

func Log

func Log(logD LoggingData, level, event, msg string)

Log in json format

func LogNew

func LogNew(level, event, msg string)

LogNew is to log with a new struct

func MountRoute

func MountRoute(router *gin.RouterGroup)

MountRoute func will mount all rest routes

Types

type IncludeItem

type IncludeItem struct {
	Type       string      `json:"type"`
	Attributes interface{} `json:"attributes"`
}

IncludeItem included item for jsonapi

type ItemDataGen

type ItemDataGen struct {
	Type       string      `json:"type"`
	ID         string      `json:"id"`
	Attributes interface{} `json:"attributes"`
}

ItemDataGen General

type JsonapiCreateEntityBody

type JsonapiCreateEntityBody struct {
	Data struct {
		Type          string        `json:"type"`
		ID            string        `json:"id"`
		Attributes    SampleEntity  `json:"attributes"`
		Relationships Relationships `json:"relationships" binding:"required"`
	} `json:"data"`
}

JsonapiCreateEntityBody jsonapi.org top wrap for request

type JsonapiDataGen

type JsonapiDataGen struct {
	Data []*ItemDataGen `json:"data"`
	Meta interface{}    `json:"meta"`
}

JsonapiDataGen jsonapi.org top wrap

type JsonapiError

type JsonapiError struct {
	APIErrors []*JsonapiErrorItem `json:"errors"`
}

JsonapiError jsonapi.org error item

type JsonapiErrorItem

type JsonapiErrorItem struct {
	Status string `json:"status"`
	Source string `json:"source"`
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

JsonapiErrorItem jsonapi.org error wrap

type LoggingData

type LoggingData struct {
	Timestamp string `json:"@timestamp,omitempty"`
	Service   string `json:"service,omitempty"`
	Thread    string `json:"thread,omitempty"`
	IP        string `json:"ip,omitempty"`
	Env       string `json:"env,omitempty"`
	Server    string `json:"server,omitempty"`

	Level        string      `json:"level,omitempty"`
	Event        string      `json:"event,omitempty"`
	Message      string      `json:"message,omitempty"`
	ID           string      `json:"Id,omitempty"`
	Raw          string      `json:"raw,omitempty"`
	RawInterface interface{} `json:"rawInterface,omitempty"`
}

LoggingData struct for structured loggin

type Meta

type Meta struct {
	Total int64 `json:"total"`
	Max   int64 `json:"max"`
}

Meta jsonapi

type Relationships

type Relationships struct {
	User RelationshipsUser `json:"user"`
}

Relationships user data

type RelationshipsUser

type RelationshipsUser struct {
	Data RelationshipsUserData `json:"data"`
}

RelationshipsUser user data

type RelationshipsUserData

type RelationshipsUserData struct {
	Type string `json:"type"`
	ID   string `json:"id" binding:"required"`
}

RelationshipsUserData user data

type SampleEntity

type SampleEntity struct {
	ID      string    `json:"id,omitempty"`
	Name    string    `json:"name,omitempty"`
	UserID  string    `json:"userid,omitempty" binding:"required"`
	Created time.Time `json:"created,omitempty"`
	Updated time.Time `json:"updated,omitempty"`
	Status  string    `json:"status,omitempty"`
}

SampleEntity sample data to save

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL