utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyReq keyRequest

Functions

func RandomStr

func RandomStr() (string, error)

func SaveRequestContext

func SaveRequestContext(cxt context.Context, r RequestResponse) context.Context

Types

type Hash

type Hash struct{}

func (*Hash) CompareHashAndPassword

func (h *Hash) CompareHashAndPassword(passwordStr string, password string, salt string) bool

func (*Hash) GenerateFromPassword

func (h *Hash) GenerateFromPassword(password string, salt string) (string, error)

type JwtClaims

type JwtClaims struct {
	Role string `json:"role"`
	jwt.RegisteredClaims
}

type JwtService

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

func NewJwtServer

func NewJwtServer(secretKey string, expireAt int) *JwtService

func (*JwtService) IssueToken

func (j *JwtService) IssueToken(ctx context.Context, sub string, tid string, role Role) (*TokenResponse, error)

func (JwtService) ParseToken

func (j JwtService) ParseToken(ctx context.Context, tokenStr string) (*JwtClaims, error)

type PageIndex

type PageIndex struct {
	Limit  int
	Offset int
}

type RequestResponse

type RequestResponse struct {
	Sub string
	Tid string
}

func GetRequestContext

func GetRequestContext(cxt context.Context) RequestResponse

func NewRequestResponse

func NewRequestResponse(sub string, tid string) *RequestResponse

type Role

type Role string
const (
	RoleAdmin Role = "admin"
	RoleUser  Role = "user"
)

type SiteMap

type SiteMap struct {
	Slugs []SiteMapData
}

func NewBusinessSiteMap

func NewBusinessSiteMap(slugs []SiteMapData) *SiteMap

func (*SiteMap) BusinessSiteMap

func (s *SiteMap) BusinessSiteMap(cxt context.Context, loc string, changeFreq string, priviority string) *Urlset

type SiteMapData

type SiteMapData struct {
	Slug      string
	UpdatedAt time.Time
}

type Token

type Token struct {
	Token    string `json:"token"`
	ExpireAt int    `json:"expire_at"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken Token  `json:"access_token"`
	RefeshToken *Token `json:"refesh_token"`
}

type UID

type UID struct {
	LocalID  uint32
	ObjectID uint
}

func DecodeFromBase58

func DecodeFromBase58(fakeUID string) *UID

func NewUID

func NewUID(localID uint32, objectID uint) *UID

func (*UID) ToBase58

func (u *UID) ToBase58() string

type Url

type Url struct {
	Loc        string `xml:"loc"`
	LastMod    string `xml:"lastmod,omitempty"`
	ChangeFreq string `xml:"changefreq,omitempty"`
	Priority   string `xml:"priority,omitempty"`
}

Url struct định nghĩa 1 URL trong sitemap loc: URL đầy đủ ví dụ https://example.com/all_blog LastMod: Thời gian cập nhật lần cuối ChangeFreq: Tuần suất thay đổi ví dụ: always hourly daily weekly monthly yearly never Priority: Độ ưu tiên khi Search (thường dựa trên bài blog hoặc bài hay nhất trong chủ đề đang tìm)

type Urlset

type Urlset struct {
	XMLName xml.Name `xml:"urlset"`
	Xmlns   string   `xml:"xmlns,attr"`
	Urls    []Url    `xml:"url"`
}

Urlset struct theo chuẩn sitemap Khi marshal bằng package Go encoding/xml, nó sẽ tạo: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> XMLName xác định root tag là: <urlset> Xmlns field này là XML attribute => sinh ra xmlns="..." Urls []Url mỗi phần tử sẽ thành: <url>

Jump to

Keyboard shortcuts

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