app

package
v0.0.0-...-db28b0c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: Unlicense Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	AuthHeaderKey = "Authorization"
	SessionKey    = "gAuth"
)
View Source
const CtxKey = "ctx"

Variables

View Source
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

View Source
var ExampleCreatedUpdated = CreatedUpdated{
	User: CreatedUpdatedUser{
		ID:    "3fa85f64-5717-4562-b3fc-2c963f66afa6",
		Name:  "Fulan",
		Email: "user@email.com",
	},
	Time: time.Now(),
}
View Source
var ExamplePageContext = PageContext{
	Page:       1,
	PerPage:    20,
	TotalPages: 1,
}
View Source
var Firebaseclient *fcm.Client
View Source
var NewRelicApp *newrelic.Application

Functions

func ConnectDB

func ConnectDB(connName string, c db.Config) error

func Decrypt

func Decrypt(text string) (string, error)

func DiffDate

func DiffDate(a, b time.Time) (year, month, day, hour, min, sec int)

func DigitLen

func DigitLen(number int) int

func Encrypt

func Encrypt(text string) (string, error)

func ErrorHandler

func ErrorHandler(c *fiber.Ctx, err error) error

func ErrorMessage

func ErrorMessage(detail interface{}, defaultMessage string) string

func ExportExcel

func ExportExcel(judul string, l []string, isi [][]interface{}) (string, error)

func FloatPrecision

func FloatPrecision(num float64, precision int) float64

func GetTrace

func GetTrace(skip int) map[string]string

func IsCodeExists

func IsCodeExists(ctx *Ctx, tableName, fieldName, code string) error

func IsValid

func IsValid(v interface{}, tag string) bool

func NewApp

func NewApp(cfg ...grest.App) *grest.App

func NewCode

func NewCode(tx *gorm.DB, tableName, fieldName, baseName string) string

func NewErrorHandler

func NewErrorHandler(c *fiber.Ctx, statusCode int, message string, detail ...interface{}) error

func ParseQuery

func ParseQuery(c *fiber.Ctx) url.Values

func RemoveExpiredToken

func RemoveExpiredToken()

func RemoveOldHistories

func RemoveOldHistories()

func SendAlert

func SendAlert(c *fiber.Ctx, message string, trace map[string]string)

func StripSlashes

func StripSlashes(str string) string

func ToString

func ToString(v interface{}) string

func Validate

func Validate(lang string, v interface{}) error

Types

type AclKeysctx

type AclKeysctx struct {
	db.NullJSON
	Data map[string]bool
}

type Action

type Action struct {
	Method    string
	EndPoint  string
	CompanyID string
	DataID    string
	Referer   string
}

type BadRequest

type BadRequest struct {
	Error struct {
		Code    int    `json:"code" example:"400"`
		Message string `json:"message" example:"A validation exception occurred."`
	} `json:"error"`
}

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 CreatedUpdatedUser struct {
	ID    string `json:"id"    format:"uuid"`
	Name  string `json:"name"  example:"Fulan"`
	Email string `json:"email" example:"user@email.com"`
}

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 NewCtx

func NewCtx(c *fiber.Ctx) (*Ctx, error)

func (*Ctx) DB

func (c *Ctx) DB(connName ...string) (*gorm.DB, error)

func (*Ctx) TxBegin

func (c *Ctx) TxBegin() error

func (*Ctx) TxCommit

func (c *Ctx) TxCommit()

func (*Ctx) TxRollback

func (c *Ctx) TxRollback()

type Deleted

type Deleted struct {
	Code    int    `json:"code"    example:"200"`
	Message string `json:"message" example:"Data has been deleted"`
}

type Forbidden

type Forbidden struct {
	Error struct {
		Code    int    `json:"code" example:"401"`
		Message string `json:"message" example:"User doesn't have permission to access the resource."`
	} `json:"error"`
}

type GeneralResponse

type GeneralResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type History

type History struct {
	Ctx         *Ctx     `gorm:"-"`
	Keys        []string `gorm:"-"`
	ID          string
	EndPoint    string
	Method      string
	Description string
	DataID      string
	UserID      string
	OldValue    string
	NewValue    string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

func (History) Create

func (h History) Create()

func (History) Process

func (h History) Process()

func (History) TableName

func (History) TableName() string

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"`
}
func (l *ListModel) SetLink(c *fiber.Ctx)

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

type LoggerImpl struct {
	zerolog.Logger
}

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 PageContext struct {
	Page       int `json:"page"        example:"1"`
	PerPage    int `json:"per_page"    example:"20"`
	TotalPages int `json:"total_pages" example:"1"`
}

type Session

type Session struct {
	AccessToken    string    `json:"access_token,omitempty"`
	RefreshToken   string    `json:"refresh_token,omitempty"`
	ExpireTimeUnix int64     `json:"expires_in,omitempty"`
	ExpiredAt      time.Time `json:"expired_at,omitempty"`
	User           UserToken `json:"user,omitempty"`
}

func (Session) Parse

func (s Session) Parse(encryptedSession string) Session

func (Session) SetCookie

func (s Session) SetCookie(c *fiber.Ctx)

type SettingTable

type SettingTable struct {
	Key   string `gorm:"primaryKey"`
	Value string `gorm:"column:json_value"`
}

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) TableName

func (Token) TableName() string

func (Token) TableVersion

func (Token) TableVersion() string

type Unauthorized

type Unauthorized struct {
	Error struct {
		Code    int    `json:"code" example:"401"`
		Message string `json:"message" example:"Invalid authorization credentials."`
	} `json:"error"`
}

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

func (UserPLT) TableAliasName() string

func (UserPLT) TableName

func (UserPLT) TableName() string

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

func (UserRoles) TableAliasName() string

func (UserRoles) TableName

func (UserRoles) TableName() string

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) SetFilter

func (u *UserToken) SetFilter()

func (*UserToken) SetRelation

func (u *UserToken) SetRelation()

func (*UserToken) SetSort

func (u *UserToken) SetSort()

func (UserToken) TableAliasName

func (UserToken) TableAliasName() string

func (UserToken) TableName

func (UserToken) TableName() string

func (UserToken) TableVersion

func (UserToken) TableVersion() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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