gourl

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

gourl

GoDoc pipeline status coverage report codecov Go Report Card

gourl is a serialization framework for golang. It converts the fields of a struct into a URL parameters compatible format.

Example

type Test struct {
    NumberField int    `url:"numberField"`
    TextField   string `url:"textField"`
}

test := Test{NumberField: 1, TextField: "hey"}

// returns the struct as []byte
byteData, err := gourl.Marshal(test)
text := string(byteData) // numberField=1&textField=hey

// returns the struct as url.Values
values, err := gourl.Values(test)
values.Encode() // numberField=1&textField=hey

Features

The following data types are supported:

  • bool
  • float32, float64
  • int, int8, int16, int32, int64
  • string

Following tags are supported:

  • Ignore fields in struct for serialization
type Test struct {
    IgnoredField string `url:"-"`
}
  • Ignore the field if
    • pointer type is nil
    • type string is empty
    • type int or float is 0
    • type boolean is false
type Test struct {
    EmptyString string `url:"emptyString,omitempty"`
}

License

Copyright 2019 Martin Riedl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal converts a struct into a URL parameter compatible byte string.

func Values

func Values(v interface{}) (url.Values, error)

Values converts a struct into a map.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL