我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

防止为空(或数据库中的空字符串值)

I'm using PostgreSQL and GORM in my Go app.

I thought that using the sql tab of sql:"not null" would do the trick of preventing a null entry, but when go initializes structs with a string type then it defaults to an empty string which is not the same as null in the db.

I am wondering if there is a way to prevent this from happening in a struct definition so I wouldn't have to strictly enforce it at all levels in the application code.

近期文章

  • 如何在Go中获取用户生成的节俭对象的内存大小
  • 如何在Golang中强制Windows Godoc更新本地Web服务器上的私有软件包文档?
  • Go导入软件包:go(-compiler gccgo)中找到的pkg,gccgo中找不到
  • 如何正确将XML解组到Go结构
  • 将Swagger与现有API集成
  • 缓冲/无缓冲的go通道和死锁
  • 虹膜错误-未解决的“获取”
  • 尽快将SQL结果转换为JSON
  • 不能在http.Get的参数中使用baseURL(类型* url.URL)作为类型字符串
  • 半异步代码逻辑
  • 使用TLS / SSL可信证书可提高性能
  • 使用Go / Datastore显示网页浏览量的经济高效方法
  • golang:协程和通道的奇怪问题
  • 如何在Go中将模板呈现为多种布局?
  • 如果外部元素在GO中不相同,如何将嵌套的json解组到结构
  • 很多连接都处于等待和关闭阶段
  • 我的hashmap实现的性能改进
  • Golang程序在写入完成之前关闭文件
  • 运行测试时“无法创建临时输出文件”
  • Codis-Redis集群代理安装

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华