起步
想在使用 GORM 时使用自定义类型必然事出有因,一般可有以下两种方式:
方法 1:
type MyString string
方法 2:
type MyString struct { string }
当需求比较简单时,可采取方法1,也就是类型别名;如果需求复杂,就不得不把数据字段嵌入自定义结构体中。字段是否匿名并不重要,主要是用来承载目的数据。
当使用 fetch 函数做跨域请求时,大概率会在浏览器 Console 中看到这样一个错误信息:Access to fetch at 'xxx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
。
Iris 的中间件设计秉承了 handler,或者,你就可以说它是 handler。这也是我极为喜欢 Iris 的一个原因,竭尽全力降低使用者的记忆负担——又少记一个函数签名。
中间件粗略在 Iris - 入门食用指南 里说过了。还不够,因为使用中间件需要牢记两个点:1. 中间件的作用域; 2. 中间件的执行顺序。