helper for go app
go get github.com/erajayatech/go-helper
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"
}
import "github.com/erajayatech/go-helper"
func main() {
amountRupiah := helper.FormatRupiah(3000)
fmt.Println(amountRupiah)
}
"Rp 3.000"
import "github.com/erajayatech/go-helper"
func main() {
gender := helper.FormatGender(1)
fmt.Println(gender)
}
"M"
import "github.com/erajayatech/go-helper"
func main() {
env := helper.MustGetEnv("MODE")
fmt.Println(env)
}
"local"
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"
import "github.com/erajayatech/go-helper"
func main() {
value := helper.ExpectedInt(6.5)
fmt.Println(value)
}
6
import "github.com/erajayatech/go-helper"
func main() {
var amount int64 = 67
value := helper.ExpectedInt64(amount)
fmt.Println(value)
}
67
import "github.com/erajayatech/go-helper"
func main() {
value := helper.ExpectedString(67)
fmt.Println(value)
}
"67"
import "github.com/erajayatech/go-helper"
func main() {
value := helper.FloatToString(0.06)
fmt.Println(value)
}
"0.060000"
import "github.com/erajayatech/go-helper"
func main() {
date, err := helper.ValidateDateFormat("01-09-2010")
fmt.Println(date)
}
"01-09-2010"
import "github.com/erajayatech/go-helper"
func main() {
date, err := helper.ConvertIsoDateFormat("2022/07/10")
fmt.Println(date)
}
"10-07-2022"
import "github.com/erajayatech/go-helper"
func main() {
data, err := helper.SanitizeSpecialChar("jalan\nnamajalan\n")
fmt.Println(data)
}
"jalan namajalan"
import "github.com/erajayatech/go-helper"
func main() {
array := []string{"abc", "def"}
data, err := helper.ContainsSliceString(array,"def")
fmt.Println(data)
}
true
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