ginrest

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: Apache-2.0 Imports: 8 Imported by: 1

README

Ginrest

This is a wrapper librari for gin-gonic rest response

Use

u := c.Request.RequestURI
r := rest.New(u, "").SetGin(c)
v1 := Record{
        Title:  "Hola",
        Object: "object.overrided",
}
v2 := Extra{
        Type: "an Extra",
}
components := rest.Payload{
        "object": "override this",
        "hola":   v1,
        "mundo":  v2,
}
// println(components)
r.Res(429, components, "")

Documentation

Overview

Package ginrest objetive is to have in one place ours rest operations, as standart rest IO with norm output Author: Rolando Lucio <rolando@compropago.com,rolandolucio@gmail.com>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code int
	Msg  string
}

Error general errors response

func (*Error) Error

func (e *Error) Error() string

Error Interface implementations

type IO

type IO struct {
	Gin *gin.Context
	// contains filtered or unexported fields
}

IO struct is the base app/json output formatter according to our defined schema

func New

func New(path, object string) *IO

New initializer

func (*IO) Res

func (s *IO) Res(code int, elements Payload, msg string) *IO

Res Rest Response According to proper type params: code proper httpStatusCode elements map of structs(interfaces) to append to the json output msg if want to override http default message for status code

if elements contains a key defined on response struct it will get overrided, in case code is override will not change the response code

The method will eval which http reference is set for the output like *gin.Context, if not found it will panic

References,inspirations : Eduardo Aguilar's Generator https://kev.inburke.com/kevin/golang-json-http/ http://attilaolah.eu/2014/09/10/json-and-struct-composition-in-go/ http://attilaolah.eu/2013/11/29/json-decoding-in-go/ http://eagain.net/articles/go-dynamic-json/ http://gregtrowbridge.com/golang-json-serialization-with-interfaces/

func (*IO) SetGin

func (s *IO) SetGin(c *gin.Context) *IO

SetGin method implementation

type Payload

type Payload map[string]interface{}

Payload map for multiple inputs

Jump to

Keyboard shortcuts

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