anogo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 11 Imported by: 4

README

AnoGo

AnoGo is an util package for Go, used by most A-Novel repositories.

go get github.com/a-novel/anogo

Map functions

The following functions refer to map-like go types and their usage.

ToMap functions

Perform conversions between map-like values.

Function Arguments
ToMap() v interface{}
ptr pointer
ToMapInterface() v interface{}
ToMapString() v interface{}

Each function may return any of the following errors:

  • anogo.ErrIsNotPtr
  • anogo.ErrIsNestedPtr
  • anogo.ErrIsNotMappable
  • anogo.ErrCannotMarshal
  • anogo.ErrCannotUnmarshal

Flatten

Flatten a map-like object.

flattened, err := anogo.Flatten(data)

Data should be either of type struct or map.

It may return any of the following errors:

  • anogo.ErrCannotMarshal
  • anogo.ErrCannotUnmarshal

Pointer functions

The following functions refer to pointers and their usage.

IsPtr

This function will return an error if the value passed as an argument doesn't represent a direct pointer to a defined value. Nested pointers are also refused.

err := anogo.IsPtr(value)

It may return any of the following errors:

  • anogo.ErrIsNotPtr
  • anogo.ErrIsNestedPtr

IsSlicePtr

This function will return an error if the value passed as an argument doesn't represent a slice of pointers. Nested pointers are also refused for slice type.

err := anogo.IsPtr(value)

It may return any of the following errors:

  • anogo.ErrIsNotPtr
  • anogo.ErrIsNestedPtr
  • anogo.ErrIsNotSlice

License

2021, A-Novel MIT License.

Documentation

Index

Constants

View Source
const (
	ErrIsNotPtr                 = "err_is_not_ptr"
	ErrIsNestedPtr              = "err_is_nested_ptr"
	ErrIsNotSlice               = "err_is_not_slice"
	ErrIsNotMappable            = "err_is_not_mappable"
	ErrCannotMarshal            = "err_cannot_marshal"
	ErrCannotUnmarshal          = "err_cannot_unmarshal"
	ErrCannotReadFilePath       = "err_cannot_read_path_file"
	ErrCannotOpenConfigFile     = "err_cannot_open_config_file"
	ErrCannotParseConfigFile    = "err_cannot_parse_config_file"
	ErrCannotCreateRequest      = "err_cannot_create_post_request"
	ErrRequestFailed            = "err_request_failed"
	ErrCannotParseRequestBody   = "err_cannot_parse_request_body"
	ErrUnexpectedResponseStatus = "err_unexpected_response_status"
	ErrUnexpectedResponse       = "err_unexpected_response"
)

Variables

This section is empty.

Functions

func Delete added in v0.2.0

func Delete(url string, payload interface{}, headers Header) (int, []byte, *errors.Error)

func Flatten added in v0.1.3

func Flatten(data interface{}) (map[string]interface{}, *errors.Error)

Flattens a map-like object.

May return:

  • ErrIsNotPtr
  • ErrIsNestedPtr
  • ErrIsNotMappable
  • ErrCannotMarshal
  • ErrCannotUnmarshal

func Get added in v0.2.0

func Get(url string, headers Header) (int, []byte, *errors.Error)

func GetExecPath added in v0.1.4

func GetExecPath() (string, *errors.Error)

Return go executable path.

May return:

  • ErrCannotReadFilePath

func IsPtr

func IsPtr(ptr interface{}) *errors.Error

Check if value is a pointer.

May return:

  • ErrIsNotPtr
  • ErrIsNestedPtr

func IsSlicePtr added in v0.1.1

func IsSlicePtr(ptr interface{}) *errors.Error

Check if slice is a slice of pointers.

May return:

  • ErrIsNotSlice
  • ErrIsNotPtr
  • ErrIsNestedPtr

func Post added in v0.2.0

func Post(url string, payload interface{}, headers Header) (int, []byte, *errors.Error)

func Put added in v0.2.0

func Put(url string, payload interface{}, headers Header) (int, []byte, *errors.Error)

func ReadConfig added in v0.1.5

func ReadConfig(cpath string, ptr interface{}) *errors.Error

Reads a config file and assign it to a pointer.

May return:

  • ErrCannotOpenConfigFile
  • ErrCannotParseConfigFile

func Request added in v0.2.0

func Request(method, url string, payload interface{}, headers Header) (int, []byte, *errors.Error)

func SliceEqual added in v0.1.3

func SliceEqual(a, b interface{}) bool

Check if 2 slice value are equal. Return false if any value is not of type Slice.

func StartGinTestServer added in v0.1.6

func StartGinTestServer(routers []func(*gin.Engine)) (*httptest.Server, func(p string) string)

func TestPostJSON added in v0.1.6

func TestPostJSON(url string, body interface{}, expectedStatus int, expectedResponse map[string]interface{}) *errors.Error

func ToMap added in v0.1.2

func ToMap(v interface{}, ptr interface{}) *errors.Error

Convert v to the underlying value of ptr.

May return:

  • ErrIsNotPtr
  • ErrIsNestedPtr
  • ErrIsNotMappable
  • ErrCannotMarshal
  • ErrCannotUnmarshal

func ToMapInterface added in v0.1.2

func ToMapInterface(v interface{}) (map[string]interface{}, *errors.Error)

Convert v to a map[string]interface{}.

May return:

  • ErrIsNotPtr
  • ErrIsNestedPtr
  • ErrIsNotMappable
  • ErrCannotMarshal
  • ErrCannotUnmarshal

func ToMapString added in v0.1.2

func ToMapString(v interface{}) (map[string]string, *errors.Error)

Convert v to a map[string]string.

May return:

  • ErrIsNotPtr
  • ErrIsNestedPtr
  • ErrIsNotMappable
  • ErrCannotMarshal
  • ErrCannotUnmarshal

Types

type Header map[string]string

func (Header) JSON added in v0.2.0

func (h Header) JSON()

func (Header) Token added in v0.2.0

func (h Header) Token(token string)

func (Header) UserAgent added in v0.2.0

func (h Header) UserAgent(ua string)

type ToMapOptions added in v0.1.3

type ToMapOptions struct {
	PreservePointers bool
	PreserveStructs  bool
}

Jump to

Keyboard shortcuts

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