[ gin-swagger使用[golang] ]
发表评论
191 views
分类标签归档:Go
package main
import (
"fmt"
"reflect"
)
type User struct {
Id int
Name string
}
func (u *User) Call() {
fmt.Println("user is called ..")
fmt.Printf("%v\n", u)
}
func Topackage main
import (
"fmt"
"net/rpc"
)
type Request struct {
Num1 int
Num2 int
}
type Response struct {
Num int
}
func main() {
req := Request{Num1: 1, Num2: 2}
client, err := rpc.DialHTTP("tcp", ":8080") //添加GOPATH为以后写项目代码的路径

在GOPATH下创建, src, bin, pkg三个文件夹

在src下创建项目

项目内容案例

执行go mod init 初始化包管理器

切换项目的时候, 也要切换gopath的路径? 目前是这样的
在vscode中安装go代码提示等工具时终端输入,防止网络下载失败 设置代理: go env -w GOPROXY=https://proxy.golang.com.cn,direct
go run main.go
1.安装
go get -u "gopkg.in/yaml.v3"
2.文件setting.yaml
mysql:
host: 47.120.55.99
port: 3306
db: go_test
user: root
password: chenhaifeng
log_level: dev
config: ""
system:
host: "0.0.0.0"
port: 8080
env: debug
3.读取配置
type Config structgo get -u "github.com/gin-gonic/gin"
go run main.go
github.com/gin-gonic/gin轻量级web框架gorm.io/gorm数据库第三方包gopkg.in/yaml.v3 读取yaml配置文件github.com/sirupsen/logrus 日志配置github.com/satori/go.uuid 生成uuidgo mod init xxxx包名
# windows中终端输入
go env -w GOPROXY=https://proxy.golang.com.cn,direct