109 lines
2.0 KiB
Markdown
109 lines
2.0 KiB
Markdown
|
|
---
|
|||
|
|
aliases:
|
|||
|
|
tags:
|
|||
|
|
creation date: 2023-09-08 14:27
|
|||
|
|
modification date: 星期五 8日 九月 2023 14:27:29
|
|||
|
|
---
|
|||
|
|
# go
|
|||
|
|
|
|||
|
|
## 设计哲学
|
|||
|
|
|
|||
|
|
- 追求简洁、优雅
|
|||
|
|
- 垂直扩展:类型嵌入
|
|||
|
|
- 水平扩展:接口
|
|||
|
|
- 原生并发,轻量高效
|
|||
|
|
- select | chanel 程序级扩展
|
|||
|
|
- 面向工程,自带电池
|
|||
|
|
|
|||
|
|
## 项目工程
|
|||
|
|
|
|||
|
|
### 目录结构
|
|||
|
|
|
|||
|
|
- cmd
|
|||
|
|
- internal
|
|||
|
|
- pkg
|
|||
|
|
- test
|
|||
|
|
|
|||
|
|
### 命名规范
|
|||
|
|
|
|||
|
|
- 包 小写,单个单词
|
|||
|
|
- 包内的命名不建议含有包名
|
|||
|
|
|
|||
|
|
## 类型
|
|||
|
|
|
|||
|
|
任何类型都可以拥有方法
|
|||
|
|
|
|||
|
|
### 常量
|
|||
|
|
|
|||
|
|
无类型常量
|
|||
|
|
|
|||
|
|
对象 nil , 可直接调用函数 (单例模式)
|
|||
|
|
|
|||
|
|
## 反射
|
|||
|
|
|
|||
|
|
```go
|
|||
|
|
// emptyInterface is the header for an interface{} value.
|
|||
|
|
type emptyInterface struct {
|
|||
|
|
typ *rtype
|
|||
|
|
word unsafe.Pointer
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// rtype is the common implementation of most values.
|
|||
|
|
// It is embedded in other struct types.
|
|||
|
|
//
|
|||
|
|
// rtype must be kept in sync with ../runtime/type.go:/^type._type.
|
|||
|
|
type rtype struct {
|
|||
|
|
size uintptr
|
|||
|
|
ptrdata uintptr // number of bytes in the type that can contain pointers
|
|||
|
|
hash uint32 // hash of type; avoids computation in hash tables
|
|||
|
|
tflag tflag // extra type information flags
|
|||
|
|
align uint8 // alignment of variable with this type
|
|||
|
|
fieldAlign uint8 // alignment of struct field with this type
|
|||
|
|
kind uint8 // enumeration for C
|
|||
|
|
// function for comparing objects of this type
|
|||
|
|
// (ptr to object A, ptr to object B) -> ==?
|
|||
|
|
equal func(unsafe.Pointer, unsafe.Pointer) bool
|
|||
|
|
gcdata *byte // garbage collection data
|
|||
|
|
str nameOff // string form
|
|||
|
|
ptrToThis typeOff // type for pointer to this type, may be zero
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
# Doc
|
|||
|
|
|
|||
|
|
https://www.cntofu.com/book/73/ch2-cgo/ch2-09-static-shared-lib.md
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
# CMD
|
|||
|
|
|
|||
|
|
```shell
|
|||
|
|
go build -x F:\go\vulkan\cmd\main.go
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
# CGO
|
|||
|
|
|
|||
|
|
```shell
|
|||
|
|
go env -w CGO_ENABLED=1
|
|||
|
|
set CGO_CFLAGS=-IF:\Coding\GoModule\cgo
|
|||
|
|
set CGO_LDFLAGS=-LF:\Coding\GoModule\cgo -I:vulkan.lib
|
|||
|
|
go build -o main.exe main.go
|
|||
|
|
|
|||
|
|
#C:\Users\Administrator\AppData\Roaming\go
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
# 条件编译
|
|||
|
|
|
|||
|
|
## 标签编译
|
|||
|
|
|
|||
|
|
## 文件后缀
|
|||
|
|
|
|||
|
|
https://blog.csdn.net/wohu1104/article/details/121842932
|
|||
|
|
|