utils

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchInsertQuery

func BatchInsertQuery(tableName string, rowCount int, colCount int, cols ...[]string) string

BatchInsertQuery to create raw batch insert query.

func GetDuration

func GetDuration(duration string) (seconds int)

GetDuration to get duration in seconds. Example: "3 hr. 30 min. 20 sec." => 12620.

func GetMapKey

func GetMapKey(m map[int]string, value string) int

GetMapKey to get key from map.

func GetQuery

func GetQuery(r *http.Request, key string, defaultValue ...string) string

GetQuery to get URL query with default value.

func GetValueFromSplit

func GetValueFromSplit(str string, separator string, index int) string

GetValueFromSplit to get value from splitted string. Will return empty string if out of index.

func ResponseWithJPEG added in v0.4.2

func ResponseWithJPEG(w http.ResponseWriter, image image.Image, code int, err error)

ResponseWithJPEG to write response with JPEG format.

func ResponseWithJSON

func ResponseWithJSON(w http.ResponseWriter, code int, data interface{}, err error, meta ...map[string]interface{})

ResponseWithJSON to write response with JSON format.

func SecondToString

func SecondToString(seconds int) string

SecondToString to convert int seconds to string duration. Example: 12620 => 03:30:20.

func StrToNum

func StrToNum(strNum string) int

StrToNum to convert string number to integer including comma removal (1,234 -> 1234).

func Thousands added in v0.4.0

func Thousands(num int) string

Thousands to format int to thousands string format.

func UniqueInt

func UniqueInt(list []int) (unique []int)

UniqueInt to remove duplicate in slice.

Types

type Response

type Response struct {
	Status  int                    `json:"status"`
	Message string                 `json:"message"`
	Data    interface{}            `json:"data" swaggertype:"object"`
	Meta    map[string]interface{} `json:"meta" swaggertype:"object"`
}

Response is standard api response model.

Jump to

Keyboard shortcuts

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