consts

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 0 Imported by: 3

Documentation

Overview

Package consts defines application-wide constants including context keys, character sets, metadata keys, and social platform identifiers.

This package provides:

  • Context key constants for storing/retrieving values
  • Character sets and encoding definitions
  • Metadata field name constants
  • Social platform identifiers
  • Common application constants

Context Keys

Standard keys for storing values in context.Context:

const (
    GinContextKey = "GinContext"     // Gin context
    UserKey       = "UserID"         // User ID
    UsernameKey   = "Username"       // Username
    TraceIDKey    = "TraceID"        // Trace ID for logging
    SpanIDKey     = "SpanID"         // Span ID for tracing
)

Usage with ctxutil:

import "github.com/ncobase/ncore/consts"
import "github.com/ncobase/ncore/ctxutil"

ctx = ctxutil.SetValue(ctx, consts.UserKey, "user-123")
userID := ctxutil.GetValue(ctx, consts.UserKey)

Character Sets

Predefined character sets for various purposes:

consts.Numeric            // "0123456789"
consts.Alphabetic         // "a-zA-Z"
consts.Alphanumeric       // "a-zA-Z0-9"
consts.AlphanumericSymbol // "a-zA-Z0-9!@#$%"

Usage for validation or generation:

import "strings"

func isNumeric(s string) bool {
    return strings.ContainsOnly(s, consts.Numeric)
}

Metadata Keys

Standard metadata field names:

consts.CreatedAt   // "created_at"
consts.UpdatedAt   // "updated_at"
consts.DeletedAt   // "deleted_at"
consts.CreatedBy   // "created_by"
consts.UpdatedBy   // "updated_by"

Use for consistent field naming:

type Model struct {
    CreatedAt time.Time `json:"created_at"`
    UpdatedAt time.Time `json:"updated_at"`
}

Social Platforms

Identifiers for social authentication providers:

consts.PlatformWeChat   // "wechat"
consts.PlatformGoogle   // "google"
consts.PlatformGitHub   // "github"
consts.PlatformFacebook // "facebook"

Usage in OAuth flows:

switch provider {
case consts.PlatformGoogle:
    return googleAuth.Authenticate(token)
case consts.PlatformGitHub:
    return githubAuth.Authenticate(token)
}

Best Practices

  • Use package constants instead of string literals
  • Reference consts for consistent naming
  • Add new constants to appropriate categories
  • Document custom constant additions
  • Use typed constants where appropriate
  • Avoid duplicating constant values

Index

Constants

View Source
const (
	Number        = "0123456789"                    // Numbers
	Lowercase     = "abcdefghijklmnopqrstuvwxyz"    // Lowercase letters
	Uppercase     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"    // Uppercase letters
	Symbol        = "!#$%&()*+,-./:;<=>?@[]^_`{|}~" // Symbols
	NumLower      = Number + Lowercase              // Numbers + Lowercase letters
	NumUpper      = Number + Uppercase              // Numbers + Uppercase letters
	LowerUpper    = Lowercase + Uppercase           // Lowercase + Uppercase letters
	NumLowerUpper = Number + Lowercase + Uppercase  // Numbers + Lowercase + Uppercase letters
	All           = NumLowerUpper + Symbol          // Combination of all

	URLSafeBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
)

Character sets

View Source
const (
	PrimaryKey     = NumLowerUpper
	PrimaryKeySize = 16
)
View Source
const (
	// SocialWechat Wechat
	SocialWechat = "wechat"
	// SocialQQ QQ
	SocialQQ = "qq"
	// SocialWeibo Weibo
	SocialWeibo = "weibo"
	// SocialGithub Github
	SocialGithub = "github"
)
View Source
const AuthorizationKey string = "Authorization"

AuthorizationKey Authorization header key

View Source
const BearerKey string = "Bearer "

BearerKey Bearer token prefix

View Source
const GinContextKey = "gin-context"

GinContextKey gin context key

View Source
const SpaceKey string = "x-md-sid"

SpaceKey global space id SpaceKey = XMdDomainKey

View Source
const TokenKey string = "x-md-token"

TokenKey global token

View Source
const TotalKey string = "x-md-total"

TotalKey result total with response

View Source
const TraceKey string = "x-md-trace"

TraceKey global trace id

View Source
const UserEmailKey = "x-md-email"

UserEmailKey global user email

View Source
const UserIsCertifiedKey = "x-md-is-certified"

UserIsCertifiedKey global user is certified

View Source
const UserKey string = "x-md-uid"

UserKey global user id

View Source
const UserStatusKey = "x-md-status"

UserStatusKey global user status

View Source
const UsernameKey string = "x-md-uname"

UsernameKey global username

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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