This repository has been archived on 2026-01-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
docs/prompts_server.txt
2024-08-12 15:32:16 +08:00

123 lines
7.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

prompts_server.txt
现在我们需要增加一个函数 QueryUserBenefits它的输入参数与 QueryUserBenefits 类似ID保持一致增加一个 datestr 参数,它的格式类似于 '20240705', 默认值是'*'。函数的作用是删除 ID:datastr的redis key如果datestr为默认值的话则表示全部。请完成你的代码
到现在为止,我们的代码中包含了多个.go文件并且每个文件完成了不同的功能它还使用了 echo框架来处理http请求。
我们想在工程里面加入日志以更好的记录发生了什么。go.uber.org/zap 是一个高性能的日志库github.com/natefinch/lumberjack 可以进行日志文件的切割所以我们想把这两个引入到我们的代码中并且对日志格式做一定的调整比如json格式加入日期日志级别打印日志的文件和代码行等等。
现在,请你给出相关的代码。
根据我们使用的全局变量的logger.go版本我们现在需要在init()时传入一些变量使得日志可以配置。这些变量包括lumberjack.Logger中使用的Filename, MaxSize, MaxBackups, MaxAge, Compress ,以及 atomicLevel.SetLevel 使用的日志级别。
配置项会在config.toml中使用我们已经实现的config.go来完成配置的读取并且在 main.go 中获取配置调用init()时传入。
请注意,这里面可能会涉及到类型转换,比如把配置项中的 日志级别字符串,转换成 atomicLevel.SetLevel 所需要的枚举值。
type LoggerConfig struct {
// 在 Go 中,只有首字母大写的字段才能被外部包(如 viper访问。
LogFile string `mapstructure:"log_file"`
MaxSize int `mapstructure:"max_size"`
MaxBackups int `mapstructure:"max_backups"`
MaxAge int `mapstructure:"max_age"`
Compress bool `mapstructure:"compress"`
Level string `mapstructure:"level"`
}
我们在config.go 中解析toml文件的上面一段报错了显示 toml: incomplete number 这是什么问题,应该如何解决?
for _, response := range responses {
transantions, err := client.ParseSignedTransactions(response.SignedTransactions)
if err != nil {
logger.Error("ParseSignedTransactions error.", zap.Error(err))
return c.JSON(http.StatusInternalServerError, "ParseSignedTransactions error")
}
logger.Debug("transantions", zap.Any("transantions", transantions)) // 打印
//buff, _ := json.Marshal(&transantions)
//fmt.Println(string(buff))
}
transantions 的类型是 []*api.JWSTransaction。现在我们想定义一个变量它把每次for循环所产生的 transantions ,全部放到一起,形成一个大的数组。请问应该怎么写
我们在使用golang编写服务端程序使用echo框架处理http请求并返回给客户端。对于注册到echo上的每个处理函数它的返回有两种一是出错了会返回
echo.NewHTTPError(http.StatusBadRequest, err.Error())
二是正常处理了请求,返回 c.JSON(http.StatusOK, map[string]string{"translation": translation})
现在我们想统一返回格式以便于客户端进行正确的处理。我们希望返回的http状态码都是 200但返回结果是 json 数据: {"ret": %d, "message":"%s", "data":%v} 其中ret为错误吗它是一个数字data也是json格式的数据。
要实现以上的功能我们需要怎么在echo框架上注册函数并且在每个接口处理中应该怎么返回
我用了这种方法,然后在接口函数中返回 return echo.NewHTTPError(http.StatusBadRequest, "no benifits left."),可是最后的输出确是这样:
{
"message": "no benifits left."
}
{
"ret": 400,
"message": "no benifits left.",
"data": null
}
为什么,是哪里出错了吗?
timezone Asia/Shanghai
secondsfromgmt 28800
// 从苹果校验订单后插入vip表中
func UpdateOrderByVerify(ID int, AppAcountToken string, OriginTransID string, transantion *api.JWSTransaction) error {
// 写入vip表如果ID对应记录不存在则插入否则更新
}
这是我们需要完成的函数需要把数据写入到VIP表如果ID对应的记录不存在则插入否则更新写入时IsVIP为1Appstore 为'Apple'ProductID 从transantion中获取
CREATE TABLE aigrammar.vip (
ID INT UNSIGNED NOT NULL,
IsVIP INT DEFAULT 0 NULL COMMENT '1-VIP; 0-not vip',
AppStore varchar(100) DEFAULT 'apple' NULL COMMENT 'apple;google',
ProductID varchar(100) NULL,
ProductType varchar(100) NULL COMMENT 'yearly;monthly;weekly;',
Environment varchar(100) NULL COMMENT 'prod;sandbox',
PurchaseDate TIMESTAMP NULL,
Price INT NULL,
Currency varchar(100) NULL,
Storefront varchar(100) NULL COMMENT 'USA',
ExpDate TIMESTAMP NULL,
AutoRenew INT NULL COMMENT '1-yes;0-no',
OriginalTransactionID varchar(100) NULL COMMENT 'applestore originalTransactionId',
CONSTRAINT vip_pk PRIMARY KEY (ID)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci;
type JWSTransaction struct {
TransactionID string `json:"transactionId,omitempty"`
OriginalTransactionId string `json:"originalTransactionId,omitempty"`
WebOrderLineItemId string `json:"webOrderLineItemId,omitempty"`
BundleID string `json:"bundleId,omitempty"`
ProductID string `json:"productId,omitempty"`
SubscriptionGroupIdentifier string `json:"subscriptionGroupIdentifier,omitempty"`
PurchaseDate int64 `json:"purchaseDate,omitempty"`
OriginalPurchaseDate int64 `json:"originalPurchaseDate,omitempty"`
ExpiresDate int64 `json:"expiresDate,omitempty"`
Quantity int32 `json:"quantity,omitempty"`
Type IAPType `json:"type,omitempty"`
AppAccountToken string `json:"appAccountToken,omitempty"`
InAppOwnershipType string `json:"inAppOwnershipType,omitempty"`
SignedDate int64 `json:"signedDate,omitempty"`
OfferType int32 `json:"offerType,omitempty"`
OfferIdentifier string `json:"offerIdentifier,omitempty"`
RevocationDate int64 `json:"revocationDate,omitempty"`
RevocationReason *int32 `json:"revocationReason,omitempty"`
IsUpgraded bool `json:"isUpgraded,omitempty"`
Storefront string `json:"storefront,omitempty"`
StorefrontId string `json:"storefrontId,omitempty"`
TransactionReason TransactionReason `json:"transactionReason,omitempty"`
Environment Environment `json:"environment,omitempty"`
Price int64 `json:"price,omitempty"`
Currency string `json:"currency,omitempty"`
OfferDiscountType OfferDiscountType `json:"offerDiscountType,omitempty"`
}