coerce

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToBool

func ToBool(input interface{}) (bool, error)

ToBool mencoba mengubah input menjadi boolean. Sangat cerdas: mendukung true/false, 1/0, "true"/"false", "on"/"off", "yes"/"no".

func ToFloat64

func ToFloat64(input interface{}) (float64, error)

ToFloat64 mencoba mengubah input menjadi angka desimal. Mendukung string ("123.45"), integer, dll.

func ToFloat64Def

func ToFloat64Def(input interface{}, defaultVal float64) float64

Helper: Konversi ke Float64 dengan nilai default jika gagal

func ToInt

func ToInt(input interface{}) (int, error)

ToInt mencoba mengubah input menjadi integer (int). Mendukung input string angka ("123"), float bulat (123.0), dll. Gagal jika inputnya string non-angka ("budi"), object, dll.

func ToInt64

func ToInt64(input interface{}) (int64, error)

ToInt64 sama seperti ToInt tapi untuk angka yang lebih besar. Berguna untuk ID database atau timestamp.

func ToMap

func ToMap(input interface{}) (map[string]interface{}, error)

ToMap mencoba mengubah input menjadi map[string]interface{}. Berguna jika inputnya adalah struct atau JSON object.

func ToSlice

func ToSlice(input interface{}) ([]interface{}, error)

ToSlice mencoba mengubah input menjadi array of interface{}.

func ToString

func ToString(input interface{}) string

ToString mencoba mengubah input menjadi string. Hampir semua tipe bisa diubah jadi string, jadi error jarang terjadi. Nil akan menjadi string kosong "".

Types

This section is empty.

Jump to

Keyboard shortcuts

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