api

package
v0.0.0-...-fe7e701 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServiceName = "SearchAPI"

ServiceName name of service

View Source
var SourceName = "SearchAPI"

SourceName for error response

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 JsonapiSearchResultRaw

func JsonapiSearchResultRaw(result string) (string, error)

JsonapiSearchResultRaw es to jsonapi.org format Elasticsearch already responding with json, and we have so far no much changes in that. so don't want to decode and encode json to give jsonapi.org format. here the solution is done without unmarshaling, using gjson and sjson

func LogEvent

func LogEvent(thelog StructuredLog, level, event, msg string)

LogEvent in json format

func LogNew

func LogNew(level, event, msg string)

LogNew is to log with a new StructuredLog struct

func MountRoute

func MountRoute(router *gin.RouterGroup)

MountRoute func will mount all rest routes

Types

type ItemDataGen

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

ItemDataGen General

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 StructuredLog

type StructuredLog 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"`
	Account      string      `json:"account,omitempty"`
	ID           string      `json:"id,omitempty"`
	Raw          string      `json:"raw,omitempty"`
	RawInterface interface{} `json:"rawInterface,omitempty"`
}

StructuredLog struct for structured loggin

Jump to

Keyboard shortcuts

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