V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  gogogo1203  ›  全部回复第 3 页 / 共 28 页
回复总数  548
1  2  3  4  5  6  7  8  9  10 ... 28  
@BeautifulSoap 2023 年了,喜欢就用,不喜欢就换个语言,没必要抓个标准库输出。多一次运算累计起来的数量都是以亿计算的,我宁可相信 go team 是考虑过这些事的。
1 。老毕要是事先同意的话,没有必要搞得那么复杂,提前说话就行了。
2. 老毕要是被先斩后奏,不情不愿地被迫接受了这个“任务”。 第一回可能,第二回没有可能
是我迷糊了吗? 零值不是 创建 struct 的时候就有了吗??“The JSON null value unmarshals into an interface, map, pointer, or slice by setting that Go value to nil. Because null is often used in JSON to mean “not present,” unmarshaling a JSON null into any other Go type has no effect on the value and produces no error.” 自己读一读 doc 呗,unmarshaler 只是没有去改原先的零值而已。unmarshaler 要快,而不是提前做很多 validation.这些后续你可以慢慢搞。
@BeautifulSoap

```
// Create adds a Comment to the database. It returns the created Comment with
// fields like ID and DateCreated populated.
func (c Core) Create(ctx context.Context, nc NewComment, now time.Time, usrId string, tutId string) (Comment, error) {
if err := validate.Check(nc); err != nil {
return Comment{}, fmt.Errorf("validating data: %w", err)
}
parentId := &dbschema.NullString{}
if nc.ParentId == "" {
parentId.Valid = false
} else {
parentId.Valid = true
parentId.String = nc.ParentId
}
dbCm := db.Comment{
ID: validate.GenerateID(),
CommenterId: usrId,
TutorialId: tutId,
ParentId: parentId,
Body: nc.Body,
DateCreated: now,
DateUpdated: now,
}
if err := c.store.Create(ctx, dbCm); err != nil {
return Comment{}, fmt.Errorf("create: %w", err)
}

return toComment(dbCm), nil
}

```

web 到业务逻辑 然后再到 db 层,json tag 校验是必备的。sql.NullString sql.NullInt 都不是简单的 struct ,理论上不存在 go 后端不查 null 的,因为必须确认. 你们是不是用了什么 orm 一把梭了.
@delacey 我看过比较好的方式是 前端来的 json 用一个 struct, 校验完转成 db 专用的另一个 struct, db 查询返回的又用另外一个新的 struct. 前端更新某个 field , 又用一个专属的 struct. 用 go 写 curd 后台,做得最多的就是各个 struct 之间转来转去。
// Decode reads the body of an HTTP request looking for a JSON document. The
// body is decoded into the provided value.
//
// If the provided value is a struct then it is checked for validation tags.
func Decode(r *http.Request, val interface{}) error {
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()
if err := decoder.Decode(val); err != nil {
return err
}

return nil
}



type NewComment struct {
Body string `json:"body" validate:"required"`
ParentId string `json:"parentId"`
}




....
var nc comment.NewComment
if err := web.Decode(r, &nc); err != nil {
return fmt.Errorf("unable to decode payload: %w", err)
}

....

很久没有写 go 了,go 不至于连个 json 不能处理吧
191 天前
回复了 gogogo1203 创建的主题 程序员 [求推荐] chatgpt wrapper
@strawberrydafu 这个强, 这么多 stars 是真少见
我用了 3 年的 xmind ,已经一年多没打开了。
1. 思维导图节点一多,整个导图就失去作用了。节点太少也是没有作用. 思维导图就在两个状态里来回颠簸。
2. 单个文件的形式建立不起来个人知识库, 也不好搜索。
3. 大部分的笔记和信息都是搜集的时候爽,但是绝大部分都不会再次被打开。
苹果和 Unity 的 Vision Pro 合作是不是让 unity 飘了,想着提前占位,开创 per install 先河。
194 天前
回复了 xingfa 创建的主题 Python 如何实现一个网页气泡🫧效果?
https://react-grid-layout.github.io/react-grid-layout/examples/0-showcase.html 用 grids 自己写一个比例应该也可以,就是字体要自适应
196 天前
回复了 willin 创建的主题 分享创造 准备把我的 npm 包 v0 捐赠给 Vercel。
@willin 白倦了 怎么也得要几个 private beta 的测试名额吧
196 天前
回复了 willin 创建的主题 分享创造 准备把我的 npm 包 v0 捐赠给 Vercel。
这是 AI 自动生成 UI 代码,,,,,,,,,,,,,
196 天前
回复了 willin 创建的主题 分享创造 准备把我的 npm 包 v0 捐赠给 Vercel。
https://v0.dev/ 原来是要给自己家的所有开源项目做个导航. 估计是先买了 v0 域名 再保险一下 npm 包。
196 天前
回复了 zhuoyue100 创建的主题 Go 编程语言 怎么提升 golang 开发水平
William Kennedy (Bill) 是 Go 语言实战的作者之一.这本书应该是 国内大家接触到的第一本 go 教程。
196 天前
回复了 zhuoyue100 创建的主题 Go 编程语言 怎么提升 golang 开发水平
https://github.com/ardanlabs/service 最强的 go 教程的 repo ,课程很贵,repo 免费。middleware, error 处理方式,整个 app 的架构,数据库的 versioning 到 docker 部署。虽然我有一段时间没有写 go 后台了, 但是这个 repo 是真的很惊艳。主要它易懂,所有 engineering 的决定都让我觉得太合理了。
196 天前
回复了 besscroft 创建的主题 分享创造 开源项目做个小推广,嗯学英语~
@huihuiHK 所有的技能都需要坚持, 这不是工具能解决的范畴
196 天前
回复了 besscroft 创建的主题 分享创造 开源项目做个小推广,嗯学英语~
我觉得可以有一个设置, 只显示英式或者英式其中之一. 大部分情况下用户只会学一种
198 天前
回复了 willin 创建的主题 分享创造 准备把我的 npm 包 v0 捐赠给 Vercel。
我就好奇 vercel 拿到 ai 这个包名花了多少钱。
1  2  3  4  5  6  7  8  9  10 ... 28  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3624 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 95ms · UTC 04:34 · PVG 12:34 · LAX 21:34 · JFK 00:34
Developed with CodeLauncher
♥ Do have faith in what you're doing.