Version: v0.0.0-...-afa1830 Latest Latest

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

Go to latest
Published: Apr 13, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Info

type Info struct {
	Input  []string
	Output []string
	Model  interface{}

Info contains fields to patch and model with patched data. See Map for more information.

func (*Info) Whitelist

func (i *Info) Whitelist(whitelistFields []string)

Whitelist fields given in parameters from the Info Input member it also removes elements saved at same position in Output slice.

type Map

type Map struct {
	Invalid bool
	// contains filtered or unexported fields

Map represents a mapping between structure tag values and their corresponding struct field names Input map is set using "From" methods, Output map is set using "To" methods patch.Map are generated by a global mapper, which is configured to look for specific struct tag for input and output As an example, a patch.Map of this model (with a mapper using json & sql tags):

type TestModel struct {
     First string `json:"json_first,omitempty" sql:"db_first"`
     Second string `json:"json_second" sql:"db_second"`
     Third string
     Fourth string `sql:"db_fourth"`
     Fifth string `json:"json_fifth"`

would have an input {"json_first": "First", "json_second": "Second", "fifth_field": "Fifth"} and a output {"First": "db_first", "Second": "db_second", "Fourth": `db_fourth`} The interest of this struct is to handle resources patching from a request to final storer

func FromHTTP

func FromHTTP(req *http.Request) Map

FromHTTP decode a HTTP request into a ready-to-be-used patch.Map It does define JSON keys found inside request body as input map It ignores errors if faced, considering it should be handled outside of this function It instantiates later used output map and it does restaure body's io.Reader after consuming it

func (Map) GetInfo

func (p Map) GetInfo(model interface{}) Info

GetInfo converts a patch.Map into a patch.Info

func (Map) ToModel

func (p Map) ToModel(model interface{}) Map

ToModel does an intersection between current input map and given model input map The model patch.Map is get from mapper It builds current output map using model output map, matching input intersection

type Mapper

type Mapper struct {
	// contains filtered or unexported fields

Mapper is a component loading and saving in memory patch.Maps for requested models in real time everytime a patch.Maps is requested for a model, the mapper is involved in order to know either the model has been already mapped or not this allows us to mitigate the use of struct reflection

Jump to

Keyboard shortcuts

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