resource

package
v0.0.0-...-9528f6d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMap = iota
	TypeArray
	TypePaginator
)

Variables

View Source
var (
	DefaultWrapKey   = "data"
	DefaultAppendKey = "meta"
)

Functions

func When

func When(ok bool, value interface{}) interface{}

When determines if the given condition is true then return the value or executes the given callback.

Types

type JsonResource

type JsonResource struct {
	// contains filtered or unexported fields
}

JsonResource is a resource that can be marshalled to JSON.

func NewArray

func NewArray(c *gin.Context, resource Resource) *JsonResource

NewArray returns a new JsonResource with Array type

func NewMap

func NewMap(c *gin.Context, resource Resource) *JsonResource

NewMap returns a new JsonResource with Map type

func NewPaginator

func NewPaginator(c *gin.Context, resource Resource) *JsonResource

NewPaginator returns a new JsonResource with Paginator type

func (*JsonResource) Append

func (r *JsonResource) Append(obj gin.H) *JsonResource

Append adds a new key-value pair to the resource

func (*JsonResource) MarshalJSON

func (r *JsonResource) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*JsonResource) Response

func (r *JsonResource) Response()

Response returns the resource as a response.

func (*JsonResource) Wrap

func (r *JsonResource) Wrap(name string) *JsonResource

Warp sets the wrap name for the resource

type MissingValue

type MissingValue struct{}

MissingValue is a placeholder for a missing value.

type Resource

type Resource interface {
	ToMap(*gin.Context) gin.H
	ToArray(*gin.Context) []*JsonResource
	ToPaginator(*gin.Context) *ent.Paginator
}

Jump to

Keyboard shortcuts

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