helper

package module
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 13 Imported by: 3

README

go-helper

helper for go app

Installation

go get github.com/erajayatech/go-helper

Usage

ValidateStruct
import "github.com/erajayatech/go-helper"

// struct
type Request struct {
	Email  string `json:"email" example:"andrietrilaksono@gmail.com" validate:"required" msg:"error_invalid_email"`
	Name string `json:"name" example:"andrie" validate:"required" msg:"error_invalid_name"`
}

var RequestErrorMessage = map[string]string{
	"error_invalid_email":  "email is required",
	"error_invalid_name":  "name is required",
}

func main() {
    var (
        request Request
    )

    errorMessage := helper.ValidateStruct(request, RequestErrorMessage)

    a, _ := json.MarshalIndent(errorMessage, "", "\t")
	fmt.Print(string(a))
}
{
	"email": "email is required",
	"name": "name is required"
}
FormatRupiah
import "github.com/erajayatech/go-helper"

func main() {
	amountRupiah := helper.FormatRupiah(3000)

	fmt.Println(amountRupiah)
}
"Rp 3.000"
FormatGender
import "github.com/erajayatech/go-helper"

func main() {
	gender := helper.FormatGender(1)

	fmt.Println(gender)
}
"M"
MustGetEnv
import "github.com/erajayatech/go-helper"

func main() {
	env := helper.MustGetEnv("MODE")

	fmt.Println(env)
}
"local"
FormatInfoText
import "github.com/erajayatech/go-helper"

func main() {
	env := helper.FormatInfoText("update data","11000034","processing","system")

	fmt.Println(env)
}
"update data #11000034 processing - updated_by: system"
ExpectedInt
import "github.com/erajayatech/go-helper"

func main() {
	value := helper.ExpectedInt(6.5)

	fmt.Println(value)
}
6
ExpectedInt64
import "github.com/erajayatech/go-helper"

func main() {
	var amount int64 = 67

	value := helper.ExpectedInt64(amount)

	fmt.Println(value)
}
67
ExpectedString
import "github.com/erajayatech/go-helper"

func main() {
	value := helper.ExpectedString(67)

	fmt.Println(value)
}
"67"
FloatToString
import "github.com/erajayatech/go-helper"

func main() {
	value := helper.FloatToString(0.06)

	fmt.Println(value)
}
"0.060000"
ValidateDateFormat
import "github.com/erajayatech/go-helper"

func main() {
	date, err := helper.ValidateDateFormat("01-09-2010")

	fmt.Println(date)
}
"01-09-2010"
ConvertIsoDateFormat
import "github.com/erajayatech/go-helper"

func main() {
	date, err := helper.ConvertIsoDateFormat("2022/07/10")

	fmt.Println(date)
}
"10-07-2022"
SanitizeSpecialChar
import "github.com/erajayatech/go-helper"

func main() {
	data, err := helper.SanitizeSpecialChar("jalan\nnamajalan\n")

	fmt.Println(data)
}
"jalan namajalan"
ContainsSliceString
import "github.com/erajayatech/go-helper"

func main() {
	array := []string{"abc", "def"}
	data, err := helper.ContainsSliceString(array,"def")

	fmt.Println(data)
}
true
CreateKeyValuePairs
import "github.com/erajayatech/go-helper"

func main() {
	array := map[string]string{
				"name":  "name is required",
				"email": "email is required",
			}
	data, err := helper.CreateKeyValuePairs(array)

	fmt.Println(data)
}
name="name is required"
email="email is required"

### IsSourceJdsport
```go
import "github.com/erajayatech/go-helper"

func main() {
	value := helper.IsSourceJdsport("jdsport")

	fmt.Println(value)
}
true

### IsSourcePaymentLink
```go
import "github.com/erajayatech/go-helper"

func main() {
	value := helper.IsSourcePaymentLink("telemarketing")

	fmt.Println(value)
}
true

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckStruct

func CheckStruct(payload interface{}) (err error)

func ContainsSliceString added in v1.2.0

func ContainsSliceString(s []string, str string) bool

func ConvertIsoDateFormat added in v1.2.0

func ConvertIsoDateFormat(p string) (result string, err error)

func CreateKeyValuePairs added in v1.2.0

func CreateKeyValuePairs(m map[string]string) string

func ExpectedInt added in v1.2.0

func ExpectedInt(v interface{}) int

func ExpectedInt64 added in v1.2.0

func ExpectedInt64(v interface{}) int64

func ExpectedString added in v1.2.0

func ExpectedString(v interface{}) string

func FloatToString added in v1.2.0

func FloatToString(f float64) string

func FormatGender added in v1.2.0

func FormatGender(gender int) string

func FormatInfoText added in v1.2.0

func FormatInfoText(actionName, orderNumber, status, updatedBy string) string

func FormatRupiah added in v1.2.0

func FormatRupiah(amount int) string

func IsSourceJdsport added in v1.3.0

func IsSourceJdsport(source string) bool

func IsSourceJdsportKiosk added in v1.3.5

func IsSourceJdsportKiosk(source string) bool
func IsSourcePaymentLink(source string) bool

func IsValidSource added in v1.3.6

func IsValidSource(source string) bool

func MustGetEnv added in v1.2.0

func MustGetEnv(key string) string

func SanitizeSpecialChar added in v1.2.0

func SanitizeSpecialChar(word string) string

func SourceToStoreCodeCCM added in v1.4.0

func SourceToStoreCodeCCM(source string) (storeCode string)

func ValidateDateFormat added in v1.2.0

func ValidateDateFormat(p string) (result string, err error)

func ValidateStruct

func ValidateStruct(payload interface{}, payloadMessageError map[string]string) (errMessage map[string]string)

func ValidateStructWithError added in v1.1.0

func ValidateStructWithError(payload interface{}, payloadMessageError map[string]string) (errMessage map[string]string, err error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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