goyave: github.com/System-Glitch/goyave/helper Index | Files | Directories

package helper

import "github.com/System-Glitch/goyave/helper"


Package Files

helper.go sort.go

func Contains Uses

func Contains(slice interface{}, value interface{}) bool

Contains check if a slice contains a value.

func ContainsStr Uses

func ContainsStr(slice []string, value string) bool

ContainsStr check if a string slice contains a value. Prefer using this helper instead of Contains for better performance.

func IndexOf Uses

func IndexOf(slice interface{}, value interface{}) int

IndexOf get the index of the given value in the given slice, or -1 if not found.

func IndexOfStr Uses

func IndexOfStr(slice []string, value string) int

IndexOfStr get the index of the given value in the given string slice, or -1 if not found. Prefer using this helper instead of IndexOf for better performance.

func Only Uses

func Only(data interface{}, fields ...string) map[string]interface{}

Only extracts the requested field from the given map[string] or structure and returns a map[string]interface{} containing only those values.

For example:

 type Model struct {
   Field string
   Num   int
   Slice []float64
 model := Model{
	  Field: "value",
	  Num:   42,
	  Slice: []float64{3, 6, 9},
 res := Only(model, "Field", "Slice")


	  "Field": "value",
	  "Slice": []float64{3, 6, 9},

In case of conflicting fields (if a promoted field has the same name as a parent's struct field), the higher level field is kept.

func RemoveHiddenFields Uses

func RemoveHiddenFields(model interface{})

RemoveHiddenFields if the given model is a struct pointer. All fields marked with the tag `model:"hide"` will be set to their zero value.

For example, this allows to send user models to the client without their password field.

func SliceEqual Uses

func SliceEqual(first interface{}, second interface{}) bool

SliceEqual check if two generic slices are the same.

func ToFloat64 Uses

func ToFloat64(value interface{}) (float64, error)

ToFloat64 convert a numeric value to float64.

func ToString Uses

func ToString(value interface{}) string

ToString convert a value to string.

type HeaderValue Uses

type HeaderValue struct {
    Value    string
    Priority float64

HeaderValue represent a value and its quality value (priority) in a multi-values HTTP header.

func ParseMultiValuesHeader Uses

func ParseMultiValuesHeader(header string) []HeaderValue

ParseMultiValuesHeader parses multi-values HTTP headers, taking the quality values into account. The result is a slice of values sorted according to the order of priority.

See: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values

For the following header:



[{text/html 1} {*/* 0.7} {text/* 0.5}]



Package helper imports 6 packages (graph). Updated 2020-10-24. Refresh now. Tools for package owners.