Documentation ¶
Index ¶
- Constants
- func BoolEnv(key string) (bool, error)
- func IntEnv(key string) (int, error)
- func ParsePtrGRPCTimeToPtrTime(t *timestamppb.Timestamp) *time.Time
- func ParsePtrGRPCTimeToTime(t *timestamppb.Timestamp) time.Time
- func ParsePtrString(s *string) string
- func ParsePtrTimeToTime(t *time.Time) time.Time
- func ParseStringNil(s string) *string
- func ParseStringToFloat64(str string, def float64) float64
- func ParseStringToInt(str string, def int) int
- func ParseStringToPhone(phone, defaultRegionCode string, phoneFormat phonenumbers.PhoneNumberFormat) (string, error)
- func ParseTimeToPtrTime(t time.Time) *time.Time
- func StringEnv(key string) (string, error)
- func Stringify(str interface{}) string
- type JSON
- type JSend
- type Links
- type Meta
- type Page
Constants ¶
const ( // Bearer Bearer = "Bearer" // XRequestID HTTP request header key X-Request-ID XRequestID = "X-Request-ID" HContentType = "Content-Type" HAccept = "Accept" HJSONType = "application/json" HJSONTypeUTF8 = "application/json; charset=utf-8" )
Variables ¶
This section is empty.
Functions ¶
func ParsePtrGRPCTimeToPtrTime ¶ added in v1.11.0
func ParsePtrGRPCTimeToPtrTime(t *timestamppb.Timestamp) *time.Time
ParsePtrGRPCTimeToPtrTime Parse pointer timestamp from GRPC struct and return nil if empty or invalid timestamp
func ParsePtrGRPCTimeToTime ¶ added in v1.11.0
func ParsePtrGRPCTimeToTime(t *timestamppb.Timestamp) time.Time
ParsePtrGRPCTimeToTime parse pointer timestamp from GRPC and return new timestamp if nil or error
func ParsePtrString ¶ added in v1.8.5
ParsePtrString function check pointer string, if nil return empty string
func ParsePtrTimeToTime ¶ added in v1.11.0
ParsePtrTimeToTime parse pointer time to time, timezone UTC
func ParseStringNil ¶ added in v1.8.5
ParseStringNil function to check string if empty return nil
func ParseStringToFloat64 ¶
ParseStringToFloat64 Parse string to float64, error return default value
func ParseStringToInt ¶
ParseStringToInt Parse string to int, error return default value
func ParseStringToPhone ¶ added in v1.8.6
func ParseStringToPhone(phone, defaultRegionCode string, phoneFormat phonenumbers.PhoneNumberFormat) (string, error)
ParseStringToPhone Function to parse string to formatted phone number See details documentation in https://github.com/nyaruka/phonenumbers defaultRegionCode using ISO 3166-Alpha 2
func ParseTimeToPtrTime ¶ added in v1.11.0
ParseTimeToPtrTime parse time to pointer time, timezone UTC
Types ¶
type JSend ¶
type JSend struct { Status string `json:"status"` Message string `json:"message,omitempty"` Data interface{} `json:"data,omitempty"` Meta *Meta `json:"meta,omitempty"` Link *Links `json:"links,omitempty"` Code interface{} `json:"code,omitempty"` }
JSend used JSend format with some modification See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "meta": { "page": { "number": "page number", "size": "page size", "total": "total page" } }, "links": { "first": "first page", "next": "next page", "prev": "previous page", "last": "last page" }, "status": "message status return with success, failed, or error", "message": "return message if error", "data": "return data if success with data or failed", "code": "error status code" }
func ErrorResponse ¶ added in v1.7.0
ErrorResponse is used return response with JSON format if failure in server side See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "status": "error", "message": "error message", "code": "error code" }
func FailResponse ¶
func FailResponse(data interface{}) JSend
FailResponse is used to return response with JSON format if failure from client side See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "status": "failed", "data": [ { "field": "field", "code": "failed code", "message": "error message" } ], }
func SuccessDataResponse ¶
SuccessDataResponse used to return response JSON format if have data value See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "status": "success", "data": "response data", "meta": "optional", "links": "optional" }
func SuccessResponse ¶
func SuccessResponse() JSend
SuccessResponse used to return response with JSON format success See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "status": "success" }
type Links ¶
type Links struct { First string `json:"first,omitempty"` Next string `json:"next,omitempty"` Prev string `json:"prev,omitempty"` Last string `json:"last,omitempty"` }
Links for meta data JSON response See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "first": "first page", "next": "next page", "prev": "previous page", "last": "last page" }
func NewLinks ¶
NewLinks build new links struct See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "first": "first page", "next": "next page", "prev": "previous page", "last": "last page" }
type Meta ¶
type Meta struct {
Page *Page `json:"page,omitempty"`
}
Meta data used for JSON response See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "meta": { "page": { "number": "page number", "size": "page size", "total": "total page" } } }
func NewMeta ¶
NewMeta build new meta struct See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "meta": { "page": { "number": "page number", "size": "page size", "total": "total page" } } }
type Page ¶ added in v1.11.0
type Page struct { Number int `json:"number,omitempty"` Size int `json:"size,omitempty"` Total int `json:"total,omitempty"` }
Page pagination information data See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
func NewPage ¶ added in v1.11.0
NewPage of return data with total of data, size per page, and number page See https://jsonapi.org/ and https://github.com/omniti-labs/jsend for references
{ "page": { "number": "page number", "size": "page size", "total": "total page" } }