service

package
v0.0.0-...-1eef698 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenCode

func GenCode(userId string, longUlr string, salt string) (string, error)

GenCode

下面一通计算, 和随机生成字母数字code的区别是, 尽量保证同样的userId+longUrl每次生成的code一样, 如果userId+longUrl生成了数据库已有的code, 则加上当前时间戳字符串作为盐salt, 递归,直到生成的code数据库中没有

Types

type AddLinkParams

type AddLinkParams struct {
	UserId   string
	LongUrl  string
	Deadline time.Time
}

type AddLinkRes

type AddLinkRes struct {
	StatusCode int
	Msg        string

	Code string
}

type AddLinkSvc

type AddLinkSvc struct {
	Database component.DatabaseItf
}

func (*AddLinkSvc) Do

func (s *AddLinkSvc) Do(ctx context.Context, params AddLinkParams) (AddLinkRes, error)

type GetLinkParams

type GetLinkParams struct {
	UserId  string
	Code    string
	LongUrl string
}

type GetLinkRes

type GetLinkRes struct {
	StatusCode int
	Msg        string

	Code     string
	LongUrl  string
	Deadline time.Time
}

type GetLinkSvc

type GetLinkSvc struct {
	Database component.DatabaseItf
}

func (*GetLinkSvc) Do

func (s *GetLinkSvc) Do(ctx context.Context, params GetLinkParams) (GetLinkRes, error)

type RedirectRes

type RedirectRes struct {
	StatusCode int
	Msg        string

	Redirect bool
	LongUrl  string
}

type RedirectSvc

type RedirectSvc struct {
	Cache    component.CacheItf
	Database component.DatabaseItf
}

func (*RedirectSvc) Do

func (s *RedirectSvc) Do(ctx context.Context, code string) (RedirectRes, error)

Jump to

Keyboard shortcuts

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