Switch language
zh
Switch theme
Light
  • go-自定义-struct-转-json

    需求: 从 api 获取到 json, 本地 unmarshal 为 struct 后, 以另外的 json tag marhsal 为 json 字符串 type Student struct { Name string `json:"name"` Age int `json:"age"` } strIn := `{ "stu_name": "Jim Green", "age": 14 }` // to json strOut := `{ "name": "Jim Green", "age": 14 }` 使用到的方法 UmarshalJOSN / MarshalJSON 方法一: 通过中间 struct 变量的匿名嵌套 struct embedding (注意防止无限循环使用 alias) package main import ( "encoding/json" "fmt" ) type Student struct { Name string `json:"name"` Age int `json:"age"` } func (s *Student) UnmarshalJSON(data []byte) error { type Alias Student aux := &struct { *Alias StuName string `json:"stu_name"` }{ Alias: (*Alias)(s), } if err := json.
  • go-判断-https-ssl-证书是否过期

    package main import ( "crypto/tls" "fmt" "time" ) func main() { conn, err := tls.Dial("tcp", "blog.umesh.wtf:443", nil) if err != nil { panic("Server doesn't support SSL certificate err: " + err.Error()) } err = conn.VerifyHostname("blog.umesh.wtf") if err != nil { panic("Hostname doesn't match with certificate: " + err.Error()) } expiry := conn.ConnectionState().PeerCertificates[0].NotAfter fmt.Printf("Issuer: %s\nExpiry: %v\n", conn.ConnectionState().PeerCertificates[0].Issuer, expiry.Format(time.RFC850)) } 参考自 freecodecamp
  • php-进程线程

    进程与线程的概念: 进程是 一个时间段: CPU 上下文切换之间的程序运行时 线程是进程之中的多个程序段的运行时, 线程共享进程的地址空间 (知乎: 线程和进程的区别是什么?)[https://www.zhihu.com/question/25532384] php-fpm 是进程, 每个请求是单线程的 多个请求是并发(多线程)的
  • Duck-Type-鸭子类型

    Duck Typing is a [type system] used in dynamic languages. For example, Python, Perl, Ruby, PHP, Javascript, etc. where the type or the class of an object is less important than the method it defines. Using Duck Typing, we do not check types at all. Instead, we check for the presence of a given method or attribute. reference: geeksforgeeks 按上述来说, 鸭子类型是动态语言的特性, 在动态语言中, 类型并不重要, 重要的是类型(实例)的方法
  • 删除文件夹中的node_modules子文件夹

    package main import ( "fmt" "io" "io/fs" "os" "path" "path/filepath" ) func main() { if len(os.Args) == 1 { panic("Enter a file name") } src := os.Args[1] var pathList []string err := filepath.Walk(src, func(path string, info fs.FileInfo, err error) error { if err != nil { return err } if info.IsDir() && info.Name() == "node_modules" { return filepath.SkipDir } if info.IsDir() { return nil } path = filepath.ToSlash(path) pathList = append(pathList, path) return nil }) if err !
  • centos-部署-go-web

    编译后的文件上传至服务器, 有两个事情要做, 一是把 web 应用做成守护进程启动, 二是端口开放 使用纯净 centos7 环境(justhost.ru vps, 非阿里云环境) 1. 防火墙开放端口 1.1 查看防火墙状态 firewall-cmd --state # running 1.2 如果没有开启, 启动防火墙 systemctl start firewalld.service 1.3 开放 8080 端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent # 开放多个端口 firewall-cmd --add-port=8081-8100/tcp --permanent 1.4 重启防火墙 systemctl restart firewall.service 1.5 重载配置 firewall-cmd --reload 1.6 查看端口开启情况 netstat -nltp # 或者使用 firewall-cmd 查看 # 查看所有 firewall-cmd --list-all # 查看指定 firewall-cmd --query-port=8080/tcp 1.7 移除端口 firewall-cmd --remove-port=8080/tcp --permanent 2. supervisord 守护进程 2.
  • 不使用-struct-定义-json-字符串

    // 方法一: 生写 string jsonStr := ` "name": "Jack", "age": 25 ` // 方法二: map[string]interface{} jsonMap := map[string]interface{}{ "name": "Jack", "age": 66, } jsonByte, _ = json.Marshal(jsonMap) jsonStr = string(jsonByte) 另外 jsonStr 转 io.Reader r := strings.NewReader(jsonStr)
  • go-结构体实例化

    type Block struct { length int height int } // 方式一 var a Block a.length = 1 a.height = 2 // 方式二 b := Block{1, 2} // 方式三 c := &Block{1, 2} // 方式四 d := new(Block) d.length = 1 d.height = 2 fmt.Println(a) fmt.Println(b) fmt.Println(c) fmt.Println(d) 方式一和二 相同, 结果都是 值对象 方式三和四 相同, 结果都是指针 值和指针的不同点在于, 如果需要对 结构体的实例进行修改时, 值需要加上 &, 而 指针不需要 如果一个 struct 内容很多, 占用内存大, 应该使用 指针而不是值来进行函数间的传递. 参考 segmentfault cnblog
  • flutter-gradle-问题

    更改 google() jcenter 无效后 gradle 下载地址 https://services.gradle.org/distributions/ 参考: 快速解决 GRADLE 项目下载 gradle-*-all.zip 慢的问题
  • goland-import-包报红

    在使用 go mod 后(go 1.11 开始支持, go 1.14 全面推荐), 无需在 GOPATH 的 src 下存在项目目录, 可以随意存放. go 包依赖管理 gopath > go vender > go module, 参考 # 一文搞懂 Go Modules 前世今生及入门使用 GOPATH 则只存放第三方包, 若不设置, 默认为 /[user]/go 目录 goland 配置 GOROOT, GOPATH 及 Go Modules 结果会在 External Libraries 中多出一个 Go Modules
🍀