Documentation ¶
Index ¶
- Constants
- Variables
- func ConnectDB(connName string, c db.Config) error
- func Decrypt(text string) (string, error)
- func DiffDate(a, b time.Time) (year, month, day, hour, min, sec int)
- func DigitLen(number int) int
- func Encrypt(text string) (string, error)
- func ErrorHandler(c *fiber.Ctx, err error) error
- func ErrorMessage(detail interface{}, defaultMessage string) string
- func ExportExcel(judul string, l []string, isi [][]interface{}) (string, error)
- func FloatPrecision(num float64, precision int) float64
- func GetTrace(skip int) map[string]string
- func IsCodeExists(ctx *Ctx, tableName, fieldName, code string) error
- func IsValid(v interface{}, tag string) bool
- func NewApp(cfg ...grest.App) *grest.App
- func NewCode(tx *gorm.DB, tableName, fieldName, baseName string) string
- func NewErrorHandler(c *fiber.Ctx, statusCode int, message string, detail ...interface{}) error
- func ParseQuery(c *fiber.Ctx) url.Values
- func RemoveExpiredToken()
- func RemoveOldHistories()
- func SendAlert(c *fiber.Ctx, message string, trace map[string]string)
- func StripSlashes(str string) string
- func ToString(v interface{}) string
- func Validate(lang string, v interface{}) error
- type AclKeysctx
- type Action
- type BadRequest
- type CompanySettingTable
- type Complement
- type CreatedUpdated
- type CreatedUpdatedUser
- type Ctx
- type Deleted
- type Forbidden
- type GeneralResponse
- type History
- type ListModel
- type LogInfo
- type LoggerImpl
- type Map
- type PageContext
- type Session
- type SettingTable
- type Token
- type Unauthorized
- type UserPLT
- type UserRoles
- type UserToken
Constants ¶
const ( //YYYY-MM-DD HH:ii:ss-Timezone FormatFullDateTimeZone = "2006-01-02 15:04:05-07" FormatDatetimePsql = "2006-01-02 15:04:05.000 -0700" //YYYY-MM-DD FormatDateOnly = "2006-01-02" //hh:mm:ss FormatTimeOnly = "15:04:05" //hh:mm:00 FormatZeroSecondTimeOnly = "15:04:00" )
const ( AuthHeaderKey = "Authorization" SessionKey = "gAuth" )
const CtxKey = "ctx"
Variables ¶
var ( APP_VERSION = "22.02.041727" APP_ENV = "production" APP_PORT = "4004" //in day HISTORY_EXP = 30 JWT_KEY = []byte("f4cac8b77a8d4cb5881fac72388bb226") CRYPTO_KEY = "wAGyTpFQX5uKV3JInABXXEdpgFkQLPTf" CRYPTO_PREFIX = "GREST" DB_DRIVER = "mysql" DB_HOST = "localhost" DB_PORT = 3306 DB_DATABASE = "db_tnde" DB_USERNAME = "root" DB_PASSWORD = "" DB_MAX_OPEN_CONNS = 35 DB_MAX_IDLE_CONNS = 25 DB_CONN_MAX_LIFETIME = time.Hour // on .env = "1h". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". DB_IS_DEBUG = false REDIS_HOST = "" REDIS_PORT = "" REDIS_CACHE_DB = 3 REDIS_REPORT_DB = 3 REDIS_USERNAME = "" REDIS_PASSWORD = "" TELEGRAM_ALERT_TOKEN = "" TELEGRAM_ALERT_CHANNEL_ID = "" LOG_CONSOLE_ENABLED = false LOG_FILE_ENABLED = true LOG_FILE_FILENAME = "logs/api.log" LOG_FILE_MAX_SIZE = 200 LOG_FILE_MAX_AGE = 7 LOG_FILE_MAX_BACKUPS = 20 NEW_RELIC_LICENSE_KEY = "cbf88a837e262c02f7e84cd360a1abd9a456NRAL" NEW_RELIC_APP_LOG_ENABLED = false NEW_RELIC_APP_LOG_Forwarding_ENABLED = false ESIGN_HOST = "http://esign.pamjaya.co.id" ESIGN_USERNAME = "esign" ESIGN_PASSWORD = "qwerty" TNDE_HOST = "http://202.180.28.6" )
default config
var ExampleCreatedUpdated = CreatedUpdated{ User: CreatedUpdatedUser{ ID: "3fa85f64-5717-4562-b3fc-2c963f66afa6", Name: "Fulan", Email: "user@email.com", }, Time: time.Now(), }
var ExamplePageContext = PageContext{
Page: 1,
PerPage: 20,
TotalPages: 1,
}
var Firebaseclient *fcm.Client
var NewRelicApp *newrelic.Application
Functions ¶
func ErrorHandler ¶
func ErrorMessage ¶
func FloatPrecision ¶
func IsCodeExists ¶
func NewErrorHandler ¶
func ParseQuery ¶
func RemoveExpiredToken ¶
func RemoveExpiredToken()
func RemoveOldHistories ¶
func RemoveOldHistories()
func StripSlashes ¶
Types ¶
type BadRequest ¶
type CompanySettingTable ¶
type CompanySettingTable struct {
SettingTable
}
func (CompanySettingTable) TableName ¶
func (CompanySettingTable) TableName() string
type Complement ¶
type Complement struct { Ctx *Ctx EndPoint string Method string Reason string Model interface{} Old interface{} New interface{} DataIDKey string // dipake untuk dapetin New pake db.First(tx, model, url.Value{}.Add(DataIDKey, DataID)) DataID string DataCode string }
pake struct biar bisa ditambah sewaktu-waktu tanpa harus error
func (*Complement) AddHistory ¶
func (f *Complement) AddHistory()
func (*Complement) DeleteCache ¶
func (f *Complement) DeleteCache()
func (*Complement) Run ¶
func (f *Complement) Run()
func (*Complement) SendWebhook ¶
func (f *Complement) SendWebhook()
type CreatedUpdated ¶
type CreatedUpdated struct { User CreatedUpdatedUser `json:"user"` Time time.Time `json:"time" format:"date-time"` }
type CreatedUpdatedUser ¶
type Ctx ¶
type Ctx struct { FiberCtx *fiber.Ctx Lang string Action Action `json:"-"` Token Token `json:"-"` User UserToken `json:"-"` IsTest bool `json:"-"` IsPrintSQL bool `json:"-"` // contains filtered or unexported fields }
func (*Ctx) TxRollback ¶
func (c *Ctx) TxRollback()
type GeneralResponse ¶
type History ¶
type ListModel ¶
type ListModel struct { Count int64 `json:"count"` Page int64 `json:"page_context.page"` PerPage int64 `json:"page_context.per_page"` PageCount int64 `json:"page_context.total_pages"` LinksFirst string `json:"links.first"` LinksPrevious string `json:"links.previous"` LinksNext string `json:"links.next"` LinksLast string `json:"links.last"` Results []map[string]interface{} `json:"results"` }
type LogInfo ¶
type LogInfo struct { Error string `json:"error,omitempty"` Version string `json:"version,omitempty"` Env string `json:"env,omitempty"` Method string `json:"method,omitempty"` Path string `json:"path,omitempty"` IP []string `json:"ip,omitempty"` Slug string `json:"slug,omitempty"` Email string `json:"email,omitempty"` ClientName string `json:"client_name,omitempty"` Referer string `json:"referer,omitempty"` Trace map[string]string `json:"trace,omitempty"` }
func NewLogInfo ¶
func NewLogInfo() LogInfo
type LoggerImpl ¶
func Logger ¶
func Logger() *LoggerImpl
func (LoggerImpl) Configure ¶
func (LoggerImpl) Configure() *LoggerImpl
Configure sets up the logging framework
Even if you’re shipping your logs to a central platform, we recommend writing them to a file on your local machine first. You will want to make sure your logs are always available locally and not lostin the network. In addition, writing to a file means that you can decouple the task of writing your logs from the task of sending them to a central platform. Your applications themselves will not need to establish connections or stream your logs, and you can leave these jobs to specialized software like the Datadog Agent. If you’re running your Go applications within a containerized infrastructure that does not already include persistent storage (e.g., containers running on AWS Fargate) you may want to configure your log management tool to collect logs directly from your containers’ STDOUT and STDERR streams (this is handled differently in Docker and Kubernetes).
The output log file will be located at LOG_FILE_FILENAME and will be rolled according to configuration set.
type Map ¶
type Map map[string]interface{}
Map is a shortcut for map[string]interface{}, useful for JSON object
type PageContext ¶
type Session ¶
type SettingTable ¶
func (SettingTable) KeyField ¶
func (SettingTable) KeyField() string
func (SettingTable) MigrationKey ¶
func (SettingTable) MigrationKey() string
func (SettingTable) SeedKey ¶
func (SettingTable) SeedKey() string
func (SettingTable) TableName ¶
func (SettingTable) TableName() string
func (SettingTable) ValueField ¶
func (SettingTable) ValueField() string
type Token ¶
type Token struct { ID string `json:"-" gorm:"column:uuid;primaryKey"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at"` UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at"` AccessToken string `json:"access_token" gorm:"column:id"` ExpireTimeUnix int64 `json:"expires_in" gorm:"column:expire_time"` RefreshToken string `json:"refresh_token" gorm:"column:refresh_token"` RefreshTokenExpireTimeUnix int64 `json:"refresh_token_expires_in" gorm:"column:refresh_token_expire_time"` FirstName string `json:"first_name" gorm:"column:first_name"` LastName string `json:"last_name" gorm:"column:last_name"` Email string `json:"email" gorm:"column:email"` MobileNumber string `json:"mobile_number" gorm:"column:mobile_number"` }
func (Token) TableVersion ¶
type Unauthorized ¶
type UserPLT ¶
type UserPLT struct { db.Model ID db.NullInt64 `json:"id" db:"plt.pmk_id" gorm:"column:pmk_id;primaryKey" form:"id"` UserID db.NullInt64 `json:"-" db:"plt.pmk_plt_user_id" gorm:"column:pmk_plt_user_id" form:"-"` Name db.NullString `json:"name" db:"plt.pmk_nama" gorm:"column:pmk_nama" form:"name"` }
func (UserPLT) TableAliasName ¶
type UserRoles ¶
type UserRoles struct { db.Model ID db.NullInt64 `json:"-" db:"ug.id" gorm:"column:id;primaryKey" form:"-"` UserID db.NullInt64 `json:"-" db:"ug.user_id" gorm:"column:user_id" form:"-"` RoleID db.NullInt64 `json:"id" db:"ug.group_id" gorm:"column:group_id" form:"id"` Name db.NullString `json:"name" db:"g.name" gorm:"-" form:"name"` Description db.NullString `json:"description" db:"g.description" gorm:"-" form:"description"` IsAdmin db.NullBool `json:"is_admin" db:"g.is_admin" gorm:"-" form:"is_admin"` ACL AclKeysctx `json:"-" db:"g.acl_keys,json" gorm:"-" form:"-"` }
func (*UserRoles) SetRelation ¶
func (au *UserRoles) SetRelation()
func (UserRoles) TableAliasName ¶
type UserToken ¶
type UserToken struct { db.Model ID db.NullInt64 `json:"id" db:"u.id" gorm:"column:id" form:"id"` Username db.NullString `json:"username" db:"u.username" gorm:"column:username" form:"username"` JobTitle db.NullString `json:"jobtitle" db:"u.job_title" gorm:"column:job_title" form:"jobtitle"` IpAddress db.NullString `json:"ipaddress" db:"u.ip_address" gorm:"column:ip_address" form:"ipaddress"` CreatedOn db.NullInt64 `json:"created" db:"u.created_on" gorm:"column:created_on" form:"created"` LastLogin db.NullInt64 `json:"last_login" db:"u.last_login" gorm:"column:last_login" form:"last_login"` CreatedOnText db.NullString `json:"created" db:"u.created_on" gorm:"column:created_on"` LastLoginText db.NullString `json:"last_login" db:"u.last_login" gorm:"column:last_login"` Active db.NullBool `json:"active" db:"u.active" gorm:"column:active" form:"active"` FirstName db.NullString `json:"firstname" db:"u.first_name" gorm:"column:first_name" form:"firstname"` LastName db.NullString `json:"lastname" db:"u.last_name" gorm:"column:last_name" form:"lastname"` Phone db.NullString `json:"phone" db:"u.phone" gorm:"column:phone" form:"phone"` PictureUrl db.NullString `json:"picture" db:"u.picture" gorm:"column:picture" form:"-"` PictureFileName db.NullString `json:"picture_filename" db:"u.picture_filename" gorm:"column:picture_filename" form:"-"` ParentPmkId db.NullInt64 `json:"parent_jabatan.id" db:"u.staff_pmk_id" gorm:"column:staff_pmk_id" form:"parent_jabatan[id]"` ParentPmkName db.NullString `json:"parent_jabatan.name" db:"pj.pmk_nama" gorm:"-" form:"parent_jabatan.name"` JabatanUtamaID db.NullInt64 `json:"jabatan_utama.id" db:"ju.pmk_id" gorm:"-" form:"jabatan_utama[id]"` JabatanUtamaName db.NullString `json:"jabatan_utama.name" db:"ju.pmk_nama" gorm:"-" form:"jabatan_utama.name"` SekretarisJabatanID db.NullInt64 `json:"jabatan_sekretaris.id" db:"js.pmk_id" gorm:"-" form:"jabatan_sekretaris[id]"` SekretarisJabatanName db.NullString `json:"jabatan_sekretaris.name" db:"js.pmk_nama" gorm:"-" form:"jabatan_sekretaris.name"` PLT []UserPLT `json:"plt" db:"plt.pmk_plt_user_id=id" gorm:"-" form:"-"` Email db.NullString `json:"email" db:"u.email" gorm:"column:email" form:"email"` LdapUsername db.NullString `json:"ldap_username" db:"u.ldap_username" gorm:"column:ldap_username" form:"ldap_username"` TokenMobile db.NullText `json:"token_mobile" db:"u.token_mobile" gorm:"column:token_mobile" form:"token_mobile"` NIK db.NullString `json:"nik" db:"u.nik" gorm:"column:nik" form:"nik"` Roles []UserRoles `json:"roles" db:"ug.user_id=id" gorm:"-" form:"roles"` ACL map[string]bool `json:"acl" db:"-" gorm:"-" form:"acl"` }
func (*UserToken) SetRelation ¶
func (u *UserToken) SetRelation()