HxCore

package module
v0.0.0-...-c1f759f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: GPL-2.0 Imports: 16 Imported by: 0

README

Go-Lang용 개발 Library (구현 중...) Create by J.H.Park / 2025-09-02

Documentation

Index

Constants

View Source
const (
	None    HxResultType = iota
	Notice               = 1
	Warning              = 2
	Success              = 3
	Fail                 = 4
)

Variables

View Source
var (
	// HxDbProviderType 상수를 키(key)로, 설명을 값(value)으로 갖는 맵을 만듭니다.
	HxDbProviderDescriptions = map[HxDbProviderType]string{
		Oracle:     "Oracle Database Server",
		MSSQL:      "Microsoft SQL Server",
		MySQL:      "MySQL Server",
		MariaDB:    "MariaDB Server",
		PostgreSQL: "PostgreSQL Server",
		SQLite:     "SQLite Database",
	}
	HxDbProviderDefaultPort = map[HxDbProviderType]int{
		Oracle:     1521,
		MSSQL:      1433,
		MySQL:      3306,
		MariaDB:    3306,
		PostgreSQL: 5432,
		SQLite:     -1,
	}
)

Functions

func ConnectionString

func ConnectionString(providerType HxDbProviderType, userId string, password string, database string) string

func ConvertFloatToCommaString

func ConvertFloatToCommaString(value float64) string

func ConvertFloatToInt

func ConvertFloatToInt(value string) int

func ConvertFloatToString

func ConvertFloatToString(value float64) string

func ConvertInt64ToCommaString

func ConvertInt64ToCommaString(value int64) string

func ConvertInt64ToString

func ConvertInt64ToString(value int64) string

func ConvertIntToBool

func ConvertIntToBool(value int) bool

func ConvertIntToCommaString

func ConvertIntToCommaString(value int) string

func ConvertIntToFloat

func ConvertIntToFloat(value int) float64

func ConvertIntToInt32

func ConvertIntToInt32(value int) int32

func ConvertIntToInt64

func ConvertIntToInt64(value int) int64

func ConvertIntToString

func ConvertIntToString(value int) string

func ConvertIntToTimeUnix

func ConvertIntToTimeUnix(value int) time.Time

func ConvertStringToBool

func ConvertStringToBool(value string) bool

func ConvertStringToFloat32

func ConvertStringToFloat32(value string) float32

func ConvertStringToFloat64

func ConvertStringToFloat64(value string) float64

func ConvertStringToInt

func ConvertStringToInt(value string) int

func ConvertStringToInt64

func ConvertStringToInt64(value string) int64

func ConvertStringToNumber

func ConvertStringToNumber(value string) float64

func ConvertStringToTime

func ConvertStringToTime(value string) time.Time

func ConvertStringToTimeUnix

func ConvertStringToTimeUnix(value string) time.Time

func ConvertStringToTimeUnixFloat

func ConvertStringToTimeUnixFloat(value string) float64

func ConvertStringToTimeUnixInt

func ConvertStringToTimeUnixInt(value string) int64

func ConvertToCommaString

func ConvertToCommaString(value interface{}) string

AddCommas 함수는 어떤 숫자 타입이든 받아 쉼표를 추가한 문자열로 반환합니다.

func ConvertValueToFloat64

func ConvertValueToFloat64(v interface{}) float64

func ConvertValueToInt

func ConvertValueToInt(v interface{}) int

#region 타입 변환 헬퍼

func ConvertValueToInt64

func ConvertValueToInt64(v interface{}) int64

func ConvertValueToString

func ConvertValueToString(v interface{}) string

func ConvertValueToUInt64

func ConvertValueToUInt64(v interface{}) uint64

func DbPing

func DbPing(ctx context.Context)

func GetCamelCase

func GetCamelCase(s string) string

GetCamelCase는 문자열을 카멜 케이스로 변환합니다.

func GetConnectionDataSourceString

func GetConnectionDataSourceString(providerType HxDbProviderType, database string) string

func GetCountWithFilter

func GetCountWithFilter(slice []map[string]any, key string, value any) int

슬라이스에서 특정 키와 값이 일치하는 맵의 개수를 셉니다.

func GetDataByKeyNameWithCasing

func GetDataByKeyNameWithCasing(data any, casing HxCasing) (map[string]any, error)

func GetHxProviderDescription

func GetHxProviderDescription(provider HxDbProviderType) string

func GetJsonWithCasing

func GetJsonWithCasing(data any, casing HxCasing) ([]byte, error)

주어진 구조체를 선택한 표기법과 '원본 순서'의 JSON으로 변환합니다.

func GetMarshalIndentWithCasing

func GetMarshalIndentWithCasing(data any, casing HxCasing) ([]byte, error)

func GetMarshalWithCasing

func GetMarshalWithCasing(data any, casing HxCasing) ([]byte, error)

MarshalWithCasing은 주어진 구조체를 선택한 표기법의 JSON으로 변환합니다.

func GetNameingCase

func GetNameingCase(s string, casing HxCasing) string

func GetNowDateOnlyString

func GetNowDateOnlyString() string

func GetNowDateString

func GetNowDateString() string

func GetNowDateTimeString

func GetNowDateTimeString() string

func GetNowTimeOnlyString

func GetNowTimeOnlyString() string

func GetNumberStringFromDateStr

func GetNumberStringFromDateStr(value string) string

func GetPascalCase

func GetPascalCase(s string) string

GetPascalCase는 문자열을 파스칼 케이스로 변환합니다.

func GetQueryWherString

func GetQueryWherString(queryWhereString ...string) string

func GetRegexpMatch

func GetRegexpMatch(pattern string, str string) map[int]string

func GetRequestFormValue

func GetRequestFormValue(r *http.Request, key string) string

func GetRequestFormValueIgnoreCase

func GetRequestFormValueIgnoreCase(r *http.Request, key string) string

GetFormValueIgnoreCase는 http.Request에서 대소문자를 구분하지 않고 파라미터 값을 찾습니다. 일치하는 키가 없으면 빈 문자열을 반환합니다.

func GetSelectFilter

func GetSelectFilter(data []map[string]any, filter func(map[string]any) bool) []map[string]any

상품 슬라이스와 '필터 함수'를 인자로 받습니다. 이 '필터 함수'는 상품 하나를 받아 조건을 만족하면 true를 반환합니다.

func GetSelectGroupByCount

func GetSelectGroupByCount(slice []map[string]any, groupByKey string) map[any]int

슬라이스에서 특정 키를 기준으로 그룹화하여 각 그룹의 개수를 셉니다. data: 원본 데이터 슬라이스 ([]map[string]any) groupByKey: 그룹화의 기준이 될 맵의 키 (string) 반환값: 그룹별 개수를 담은 맵 (map[any]int)

func GetSnakeCase

func GetSnakeCase(s string) string

GetSnakeCase는 문자열을 스네이크 케이스로 변환합니다. (e.g., UserID -> user_id)

func GetStringArrayFindKeyFromMapSlice

func GetStringArrayFindKeyFromMapSlice(slice []map[string]any, findKey string) []string

func GetStringJoinFindKey2FromMapSlice

func GetStringJoinFindKey2FromMapSlice(slice []map[string]any, findKey string, sep string) string

func GetStringJoinFindKeyFromMapSlice

func GetStringJoinFindKeyFromMapSlice(slice []map[string]any, findKey string, sep string) string

func IsDate

func IsDate(value string) bool

func IsDatetime

func IsDatetime(value string) bool

func IsDatetimeUnix

func IsDatetimeUnix(value string) bool

func IsDatetimeUnixInt

func IsDatetimeUnixInt(value string) bool

func IsFloat

func IsFloat(value string) bool

func IsInt

func IsInt(value string) bool

func IsNullOrEmpty

func IsNullOrEmpty(value string) bool

func IsNullOrWhiteSpace

func IsNullOrWhiteSpace(value string) bool

func IsNumber

func IsNumber(value string) bool

func IsRegexpMatch

func IsRegexpMatch(pattern string, str string) bool

func IsString

func IsString(value string) bool

func IsTime

func IsTime(value string) bool

func Lower

func Lower(str string) string

func SetValueAppendFromMap

func SetValueAppendFromMap(m map[string][]any, key string, value interface{})

add 함수는 맵, 키, 추가할 값을 받아 알아서 처리해줍니다.

func SetValueFindKeyFromMapSlice

func SetValueFindKeyFromMapSlice(slice []map[string]any, findKey string, findValue any, setKey string, setValue any) bool

슬라이스에서 특정 조건에 맞는 맵을 찾아 값을 설정합니다. findKey, findValue: 찾으려는 맵을 식별하기 위한 조건 (예: "id", 10) setKey, setValue: 추가하거나 수정하려는 키와 값 반환값: 해당 맵을 찾아 수정했는지 여부 (bool)

func SubStr

func SubStr(str string, start int, end int) string

func Trim

func Trim(str string) string

func Upper

func Upper(str string) string

Types

type HxCasing

type HxCasing int

Casing은 JSON 키 표기법을 나타내는 타입입니다.

const (
	NormalCase HxCasing = iota
	PascalCase          // 파스칼 케이스 (e.g., UserName)
	CamelCase           // 카멜 케이스 (e.g., userName)
	SnakeCase           // 스네이크 케이스 (e.g., user_name)
	JsonCase            // json 태그가 있으면 그 값을, 없으면 Normal처럼 처리
)

func GetHxCasingFromString

func GetHxCasingFromString(s string) (HxCasing, error)

ParseHxCasing은 주어진 문자열을 HxCasing 타입으로 변환합니다. 일치하는 타입이 없으면 에러를 반환합니다.

type HxDbConfig

type HxDbConfig struct {
	Driver   string `json:"driver" env:"DB_DRIVER" envDefault:"Oracle" description:"Database 드라이버"` // Oracle, MSSQL, MySQL, ... 등을 구분할 필드
	User     string `json:"user" env:"DB_USER" description:"User ID"`
	Password string `json:"password" env:"DB_PASSWORD" description:"패스워드"`
	Host     string `json:"host" env:"DB_HOST" envDefault:"localhost" description:"Database 서버명(주소)"`
	Port     int    `json:"port" env:"DB_PORT" description:"Database 접속 PORT"`
	DBName   string `json:"dbname" env:"DB_NAME" description:"DB Name or Service Name/ID(SID) or 추가 옵션"`
}

type HxDbOracle

type HxDbOracle struct {
	// contains filtered or unexported fields
}

HxDbOracle는 IHxDb 인터페이스를 구현하는 Oracle 전용 구조체입니다.

func (*HxDbOracle) BeginTransaction

func (h *HxDbOracle) BeginTransaction() (context.Context, error)

트랜잭션 관련 메서드 (구현)

func (*HxDbOracle) Close

func (h *HxDbOracle) Close() error

Close는 DB 연결을 닫습니다.

func (*HxDbOracle) Commit

func (h *HxDbOracle) Commit() error

func (*HxDbOracle) Connect

func (h *HxDbOracle) Connect(userID string, password string, database string) (context.Context, error)

Connect는 사용자 정보로 DSN을 만들어 Oracle DB에 연결합니다.

func (*HxDbOracle) EndTransaction

func (h *HxDbOracle) EndTransaction() error

func (*HxDbOracle) Field

func (h *HxDbOracle) Field(colName string) (any, error)

Field는 f와 동일한 기능을 합니다.

func (*HxDbOracle) FieldByIndex

func (h *HxDbOracle) FieldByIndex(index int) (any, error)

FieldByIndex는 현재 레코드에서 인덱스로 컬럼 값을 가져옵니다. (Map에서는 순서가 보장되지 않으므로 주의)

func (*HxDbOracle) NextId

func (h *HxDbOracle) NextId(sequenceName string) (int64, error)

next_id는 NextId 메서드를 호출하는 별칭(alias)입니다.

func (*HxDbOracle) NextRecord

func (h *HxDbOracle) NextRecord() (int, error)

NextRecord는 next_record와 동일한 기능을 합니다.

func (*HxDbOracle) Open

func (h *HxDbOracle) Open() (int, error)

Open은 Connect와 동일한 역할을 수행 (인터페이스 호환성을 위해)

func (*HxDbOracle) Query

func (h *HxDbOracle) Query(query string, arg map[string]any) (int, error)

Query는 SELECT 문을 실행하고 그 결과를 내부 레코드셋에 저장합니다.

func (*HxDbOracle) QueryData

func (h *HxDbOracle) QueryData(query string, arg map[string]any, queryWhereString ...string) ([]map[string]any, error)

func (*HxDbOracle) RecordCount

func (h *HxDbOracle) RecordCount() (int, error)

RecordCount는 nf와 동일한 기능을 합니다.

func (*HxDbOracle) RecordSet

func (h *HxDbOracle) RecordSet() ([]map[string]any, error)

RecordSet은 저장된 전체 레코드셋을 반환합니다.

func (*HxDbOracle) Rollback

func (h *HxDbOracle) Rollback() error

func (*HxDbOracle) SetDebugMode

func (h *HxDbOracle) SetDebugMode(debug bool)

func (*HxDbOracle) WriteDebugMessage

func (h *HxDbOracle) WriteDebugMessage(str string)

type HxDbProviderType

type HxDbProviderType string
const (
	Oracle     HxDbProviderType = "Oracle"
	MSSQL      HxDbProviderType = "MS-SQL"
	MySQL      HxDbProviderType = "MySQL"
	MariaDB    HxDbProviderType = "MariaDB"
	PostgreSQL HxDbProviderType = "PostgreSQL"
	SQLite     HxDbProviderType = "SQLite"
	OCI        HxDbProviderType = "Oracle"
)

func (HxDbProviderType) ToDescriptionEx

func (drv HxDbProviderType) ToDescriptionEx() string

func (HxDbProviderType) ToStringEx

func (drv HxDbProviderType) ToStringEx() string

HxDbProviderType 타입을 그냥 string 타입으로 변환해서 반환하면 됩니다.

type HxResultType

type HxResultType int

func (HxResultType) MarshalJSON

func (r HxResultType) MarshalJSON() ([]byte, error)

func (HxResultType) String

func (r HxResultType) String() string

type HxResultValue

type HxResultValue struct {
	Result     string       `json:"result"`
	Values     any          `json:"values"`
	Message    string       `json:"message"`
	Remark     string       `json:"remark"`
	ResultType HxResultType `json:"ResultType"`
	ValueType  string       `json:"ValueType"`
	ValueCount int          `json:"ValueCount"`
}

func CreateHxResponseResult

func CreateHxResponseResult(resultType HxResultType, value any, message string, remark string) HxResultValue

func CreateHxResultValue

func CreateHxResultValue(resultType HxResultType, value any, message string, remark string) HxResultValue

func (*HxResultValue) CountEx

func (r *HxResultValue) CountEx() int

func (*HxResultValue) ToJsonBytes

func (res *HxResultValue) ToJsonBytes() ([]byte, error)

func (*HxResultValue) ToJsonBytesFromCaseingString

func (res *HxResultValue) ToJsonBytesFromCaseingString(s string) ([]byte, error)

func (*HxResultValue) ToJsonBytesFromCaseingType

func (res *HxResultValue) ToJsonBytesFromCaseingType(casing HxCasing) ([]byte, error)

func (*HxResultValue) ToJsonCamelCasingBytes

func (res *HxResultValue) ToJsonCamelCasingBytes() ([]byte, error)

func (*HxResultValue) ToJsonCaseBytes

func (res *HxResultValue) ToJsonCaseBytes() ([]byte, error)

func (*HxResultValue) ToJsonNormalCaseBytes

func (res *HxResultValue) ToJsonNormalCaseBytes() ([]byte, error)

func (*HxResultValue) ToJsonPascalCasingBytes

func (res *HxResultValue) ToJsonPascalCasingBytes() ([]byte, error)

func (*HxResultValue) ToJsonResponseWriter

func (res *HxResultValue) ToJsonResponseWriter(w http.ResponseWriter) bool

func (*HxResultValue) ToJsonSnakeCasingBytes

func (res *HxResultValue) ToJsonSnakeCasingBytes() ([]byte, error)

func (*HxResultValue) ToJsonString

func (res *HxResultValue) ToJsonString() (string, error)

func (*HxResultValue) TypeEx

func (r *HxResultValue) TypeEx() string

type HxString

type HxString string

func GetConvertStringToHxString

func GetConvertStringToHxString(s string) HxString

string을 HxString으로 변환하는 함수

func GetConvertValueToHxString

func GetConvertValueToHxString(value interface{}) HxString

func (HxString) IsRegexpMatch

func (s HxString) IsRegexpMatch(pattern string) bool

func (HxString) Lower

func (s HxString) Lower() HxString

func (HxString) String

func (s HxString) String() string

HxString을 string으로 변환하는 함수 (메서드 방식)

func (HxString) SubStr

func (s HxString) SubStr(start int, end int) HxString

func (HxString) ToBool

func (s HxString) ToBool() bool

func (HxString) ToFloat

func (s HxString) ToFloat() float32

func (HxString) ToFloat64

func (s HxString) ToFloat64() float64

func (HxString) ToInt

func (s HxString) ToInt() int

func (HxString) ToInt64

func (s HxString) ToInt64() int64

func (HxString) ToInt64ToCommaString

func (s HxString) ToInt64ToCommaString() HxString

func (HxString) ToNumber

func (s HxString) ToNumber() float64

func (HxString) ToRegexpMatch

func (s HxString) ToRegexpMatch(pattern string) map[int]string

func (HxString) ToString

func (s HxString) ToString() string

func (HxString) Trim

func (s HxString) Trim() HxString

func (HxString) Upper

func (s HxString) Upper() HxString

type IHxDb

type IHxDb interface {

	// SetDebugMode는 디버그 모드를 활성화/비활성화합니다.
	SetDebugMode(debug bool)

	Connect(userID string, password string, database string) (context.Context, error)

	//Open 데이터베이스 연결
	Open() (int, error)

	// Close는 데이터베이스 연결을 닫습니다.
	Close() error

	Query(query string, arg map[string]any) (int, error)
	QueryData(query string, arg map[string]any, queryWhereString ...string) ([]map[string]any, error)

	RecordCount() (int, error)
	RecordSet() ([]map[string]any, error)

	NextRecord() (int, error)

	Field(colName string) (any, error)
	FieldByIndex(index int) (any, error)

	BeginTransaction() (context.Context, error)
	EndTransaction() error
	Commit() error
	Rollback() error

	NextId(sequenceName string) (int64, error)
	// contains filtered or unexported methods
}

func CreateHxDb

func CreateHxDb(provider HxDbProviderType) (IHxDb, error)

func NewHxDb

func NewHxDb(provider HxDbProviderType) (IHxDb, error)

type ResultOption

type ResultOption func(*HxResultValue)

옵션 함수의 타입을 정의

func WithMessage

func WithMessage(message string) ResultOption

func WithOptionString

func WithOptionString(remark string) ResultOption

func WithValue

func WithValue(value any) ResultOption

각 옵션을 설정하는 ResultOption 타입을 반환

Jump to

Keyboard shortcuts

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