service

package
v0.0.0-...-fb77912 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDBTimeOut = 15 * time.Second
	BPasswordTable   = "table_account_data"
	BAuthTable       = "table_authenticator_data"
)
View Source
const (
	RequestTimeOutInSeconds = 30
)

Variables

This section is empty.

Functions

func GetAddr

func GetAddr() string

func InitConfig

func InitConfig()

func NewServer

func NewServer() *http.Server

func QueryAuthData

func QueryAuthData(w http.ResponseWriter, r *http.Request)

func QueryData

func QueryData(w http.ResponseWriter, r *http.Request)

QueryData 查询数据的处理函数,从 Firestore 获取数据并返回 EncodedData 实例

func TimeoutMiddleware

func TimeoutMiddleware(next http.Handler) http.Handler

func UpdateAuthData

func UpdateAuthData(w http.ResponseWriter, r *http.Request)

func UpdateData

func UpdateData(w http.ResponseWriter, r *http.Request)

UpdateData 更新数据的处理函数,将数据保存到 Firestore 并返回 EncodedData 实例

Types

type Config

type Config struct {
	Addr       string
	ProjectID  string
	DatabaseID string
	KeyFile    string
}

Config 存储应用程序的配置

type DbManager

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

DbManager 管理 Firestore 客户端

func DbInst

func DbInst() *DbManager

DbInst 获取 DbManager 实例

func (*DbManager) Close

func (dm *DbManager) Close()

func (*DbManager) CreateOrUpdateAccount

func (dm *DbManager) CreateOrUpdateAccount(updateReq *EncodedData) (*UpdateResult, error)

func (*DbManager) GetAuthByAccount

func (dm *DbManager) GetAuthByAccount(walletAddr string) (*EncodedData, error)

func (*DbManager) GetByAccount

func (dm *DbManager) GetByAccount(walletAddr string) (*EncodedData, error)

func (*DbManager) UpdateAuthData

func (dm *DbManager) UpdateAuthData(updateReq *EncodedData) (*UpdateResult, error)

type EncodedData

type EncodedData struct {
	WalletAddr  string `json:"wallet_addr" firestore:"wallet_addr" validate:"required,alphanum"`
	EncodeValue string `json:"encode_value" firestore:"encode_value" validate:"required"`
	Version     int64  `json:"version" firestore:"version" validate:"gte=0"`
}

type QueryRequest

type QueryRequest struct {
	WalletAddr string `json:"wallet_addr"  validate:"required,alphanum"`
	QueryTime  int64  `json:"current_time" validate:"required"`
	Signature  string `json:"signature" validate:"required"`
}

QueryRequest 查询数据的请求体结构

func (*QueryRequest) DataToSign

func (req *QueryRequest) DataToSign() []byte

func (*QueryRequest) Validate

func (req *QueryRequest) Validate() error

Validate 使用validator库验证 QueryRequest

type UpdateRequest

type UpdateRequest struct {
	*EncodedData `validate:"required"`
	RequestTime  int64  `json:"request_time" firestore:"_" validate:"required"`
	Signature    string `json:"signature" firestore:"_" validate:"required"`
}

func (*UpdateRequest) DataToSign

func (req *UpdateRequest) DataToSign() []byte

func (*UpdateRequest) Validate

func (req *UpdateRequest) Validate() error

Validate 使用validator库验证 EncodedData

type UpdateResult

type UpdateResult struct {
	ResultCode int   `json:"result_code"`
	LatestVer  int64 `json:"latest_ver"`
}

Jump to

Keyboard shortcuts

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