goutil

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 16 Imported by: 0

README

Installation

go get github.com/NovanHsiu/goutil

Usage

package main

import (
	"github.com/NovanHsiu/goutil"
	"fmt"
	"time"
)

func main() {
	fmt.Println(goutil.SQLTimeStringToTime(time.Now()))
}

Documentation

Index

Constants

View Source
const TimeLayout = "2006-01-02 15:04:05"

TimeLayout used to time.parse

Variables

View Source
var ErrorCodeTable = map[string][]string{

	"200.1": {"20001", "successful operation", "操作成功"},

	"400.1": {"40001", "missing parameter: @param", "缺少參數 @param"},
	"400.2": {"40002", "parameter type error: @param", "參數型別錯誤 @param"},
	"400.3": {"40003", "parameter format error: @param", "參數格式錯誤 @param"},
	"400.4": {"40004", "parameter structure error", "參數結構錯誤"},
	"400.5": {"40005", "password and confirmed password dose not match", "密碼錯誤"},
	"400.6": {"40006", atParameter, "時間區間參數安排錯誤"},
	"400.7": {"40007", "pararameter's resource not found: @param", "找不到 @param"},

	"401.1": {"40101", "authentication error@param", "登入認證失敗"},
	"401.2": {"40102", "wrong password", "密碼錯誤"},
	"401.3": {"40103", "login failed too many times, login prohibited ten minutes", "登入失敗太多次,暫時禁止登入十分鐘"},
	"401.4": {"40104", "your device not certified to using this service", "您的裝置未被認證可使用此服務"},

	"403.1": {"40301", "permission denied@param", "權限不足"},

	"404.1": {"40401", "@param not found", "找不到 @param"},

	"422.1": {"42201", "@param exists", "已定義 @param"},
	"422.2": {"42202", atParameter, "MAC已經綁定金鑰"},

	"500.1": {"50001", atParameter, "伺服器內部錯誤"},
	"500.2": {"50002", atParameter, "資料庫錯誤"},
	"500.3": {"50003", atParameter, "檔案上傳處理錯誤"},
	"500.4": {"50004", atParameter, "送簽錯誤"},
	"500.5": {"50005", atParameter, "呼叫HIS API錯誤"},
}

ErrorCodeTable record errror code and message for response

View Source
var ImageExtName = []string{".jpg", ".jpeg", ".png", ".bmp", ".gif"}

Functions

func ArrayIncludeString

func ArrayIncludeString(sl []string, v string, islike bool) bool

func ContainsString

func ContainsString(sl []string, v string) bool

ContainsString Contains find element slice contains the element or not

func ConvertChineseGender

func ConvertChineseGender(gender string) string

ConvertChineseGender convert "男", "女" to "M", "F"

func CopyFile

func CopyFile(src, dst string) error

CopyFile copy a file from source to destination path

func CreateResponse

func CreateResponse(key string) map[string]interface{}

CreateResponse create response of web api

func CreateResponseDesc added in v0.2.2

func CreateResponseDesc(key, param, desc string) map[string]interface{}

CreateResponseDesc create response of web api with parameter & description

func CreateResponseParam

func CreateResponseParam(key string, param string) map[string]interface{}

CreateResponseParam create response of web api with parameter

func Execute

func Execute(cmdstr string, args ...string) (string, string, error)

Execute execute terminal's command retrun stdout, stderr & error

func ExecuteBackground

func ExecuteBackground(cmdstr string, args ...string) (int, error)

ExecuteBackground execute terminal's command in the background retrun pid, error

func ExecuteHideWindow added in v0.2.13

func ExecuteHideWindow(cmdstr string, args ...string) (string, string, error)

ExecuteHideWindow execute terminal's command and hide window retrun stdout, stderr & error

func ExecutionDir

func ExecutionDir() string

func GetFormatTimeString

func GetFormatTimeString(t time.Time, format string) string

GetFormatTimeString set time to fomrat string example: - input: (time.Now(),"YYYY-MM-DD hh:mm:ss") - output: "2019-10-17 15:30:46"

func GetMacAddress

func GetMacAddress() string

GetMacAddress get mac address of this device

func GetMimeType

func GetMimeType(contentType string) string

GetMimeType get mimetype of file from *gin.Context.ContentType() example format of contentType: Content-Type:text/plain] multipart/form-data

func GetModuleLanguage added in v0.2.11

func GetModuleLanguage() string

func GetRandomString

func GetRandomString(length int) (rndtxt string)

GetRandomString 取得指定長度的隨機字串,長度必需大於0小於等於100,否則會回傳空字串 ""

func GetRandomTempDirName

func GetRandomTempDirName(basePath string, length int) (rndtxt string)

GetRandomTempDirName 取得指定長度且不重複的暫存資料夾路徑

func GetSystemLanguage added in v0.2.11

func GetSystemLanguage() string

GetSystemLanguage get system's language setting

Only support for detecting the following languages: en, zh-Hant, zh-Hans. (The returned names refer to the List of ISO 639-1 codes) All other languages will be treated as English.

func HasString

func HasString(sl []string, v string) bool

HasString find the same string in array

func IsImage

func IsImage(filename string) bool

IsImage check filename is image

func MatchDatePattern

func MatchDatePattern(date string) bool

MatchDatePattern check date string is match pattern "YYYY-MM-DD",ex:"2015-11-26"

func PadLeft

func PadLeft(str, pad string, length int) string

PadLeft add pad string to the left of main string

func ReadJSONConfig

func ReadJSONConfig(path string) (map[string]interface{}, error)

func RemoveDuplicateString added in v0.2.10

func RemoveDuplicateString(slice []string) []string

func RemoveSuffixVersion

func RemoveSuffixVersion(name string) string

func RocToADYear

func RocToADYear(rocDate string) string

RocToADYear ROC YYYMMDD(or YYMMDD) format to AD YYYY-MM-DD format

func SQLTimeFormatToString

func SQLTimeFormatToString(t time.Time) string

SQLTimeFormatToString turn time to sql format time in string

func SQLTimeStringToTime

func SQLTimeStringToTime(t string) (time.Time, error)

SQLTimeStringToTime turn sql fromat time string to time type

func SQLTimeStringToTimeUTCZero added in v0.2.10

func SQLTimeStringToTimeUTCZero(t string) (time.Time, error)

SQLTimeStringToTimeUTCZero turn sql fromat time string to time type and time zone is UTC+0

func SetModuleLanguage added in v0.2.11

func SetModuleLanguage(langCode string) error

SetModuleLanguage set module's language

Only support the following languages: en, zh-Hant, zh-Hans.

func SetRequestBodyParams

func SetRequestBodyParams(body io.ReadCloser) (map[string]interface{}, error)

SetRequestBodyParams turn c.Request.Body ReaderCloser to params map[string]interface{}

func TimeStamptoTime

func TimeStamptoTime(timeStampStr string) (time.Time, error)

TimeStamptoTime convert timestamp string to time

func ToRocDate

func ToRocDate(date string) string

ToRocDate change date to roc year format, ex: 1951-12-11 -> 401211

func WriteJSONConfig

func WriteJSONConfig(path string, jsonMap map[string]interface{}) 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