zoukankan      html  css  js  c++  java
  • golang 相关

    安装 code-server

    github code-server 下载 deb 包

    deb 安装包

    sudo dpkg -i code-server.deb

    修改 ~/.config/code-server 中 config.yaml 中 code-server 访问的 bind-addr password

    安装 golang

    下载 golang tar 包后得到一个名为 go 的文件夹
    解压后放到 /usr/local/ 中

    添加环境变量:
    sudo vim /etc/profile

    export PATH=$PATH:/usr/local/go/bin

    source ~/.profile

    设置 golang

    go env -w GOPROXY=https://goproxy.cn,direct
    go clean --modcache

    vscode 中
    按ctrl+shift+p 调出命令面板,输入go install tools 选Go: Install/Update Tools 然后安装全部

    结构体

    type Person struct {
    Name string json:"name"
    Age int json:"age"
    Addr string json:"addr,omitempty"
    }

    接口

    type Phone interface {
    call()
    }

    // 三种获取 field
    field := reflect.TypeOf(obj).FieldByName("Name")
    field := reflect.ValueOf(obj).Type().Field(i) // i 表示第几个字段
    field := reflect.ValueOf(&obj).Elem().Type().Field(i) // i 表示第几个字段

    // 获取 Tag
    tag := field.Tag

    // 获取键值对
    labelValue := tag.Get("label")
    labelValue,ok := tag.Lookup("label")

    func new(Type) *Type
    分配内存
    设置零值
    返回指针(重要)

    func make(t Type, size ...IntegerType) Type
    内建函数 make 用来为 slice,map 或 chan 类型(注意:也只能用在这三种类型上)分配内存和初始化一个对象
    make 返回类型的本身而不是指针,而返回值也依赖于具体传入的类型

    //切片
    a := make([]int, 2, 10)

    // 字典
    b := make(map[string]int)

    // 通道
    c := make(chan int, 10)

    func 函数名(形式参数列表)(返回值列表){
    函数体
    }

    匿名函数
    func(参数列表)(返回参数列表){
    函数体
    }

    pipline := make(chan int)

    var 实例名 sync.WaitGroup

    一个叫 Mutex, 利用它可以实现互斥锁。
    // 第一种
    var lock *sync.Mutex
    lock = new(sync.Mutex)

    // 第二种
    lock := &sync.Mutex{}

    一个叫 RWMutex,利用它可以实现读写锁。

  • 相关阅读:
    Codeforces 1132D
    Codeforces 670F
    Codeforces 670E
    Codeforces 670E
    Codeforces 670E
    Codeforces 670
    Codeforces 1138
    Codeforces 1114E
    力扣21.合并两个有序链表
    力扣538.把二叉树转换为累加树
  • 原文地址:https://www.cnblogs.com/manastudent/p/15744789.html
Copyright © 2011-2022 走看看