分享
  1. 首页
  2. 文章

Golang的学习心得1

Jony-J · · 1336 次点击 · · 开始浏览
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

  1. 对于一个的使用多个php 传统MVC框架的人来说 Beego 使用起来很简单。原生支持的Api的resetful的规范
    package controllers
    import (
     "github.com/astaxie/beego"
    )
    type ApiController struct {
     beego.Controller
    }
    //预处理方法,这个函数主要是为了用户扩展用的,这个函数会在下面定义的这些Method方法之前执行,用户可以重写这个函数实现类似用户验证之类。
    func (a *ApiController)Prepare(){
     a.Ctx.WriteString("This is the Prepare Method")
    }
    //Beego 是支持resetful 的,对号入座
    func (a *ApiController)Get() {
     a.Ctx.WriteString("This is the Get Method")
    }
    func (a *ApiController)Post() {
     a.Ctx.WriteString("This is the Post Method")
    }
    func (a *ApiController)Delete() {
     a.Ctx.WriteString("This is the Delete Method")
    }
    func (a *ApiController)Put() {
     a.Ctx.WriteString("This is the Put Method")
    }
    func (a *ApiController)Head() {
     a.Ctx.WriteString("This is the Head Method")
    }
    func (a *ApiController)Options() {
     a.Ctx.WriteString("This is the Head Methodn")
    }
    //这个函数实在执行完相应的http Method方法之后执行的,默认是空,
    // 用户可以在子Strcut中重写这个函数,执行例如数据库关闭,清理数据之类的工作
    func (a *ApiController)Finish() {
     a.Ctx.WriteString("This is the Head Finish")
    }
    
  2. golang 的多赋值特性,有需要注意的地方:
    package main
    import "fmt"
    func main(){
     x := []int{1,2,3}
     i := 0
     i,x[i] =2,i
     fmt.Println(i,x)//输出的是 2 【0 2 3】
    }
  3. go 有项目的管理工具,类似于PHP的Composer。go 原始的import 包会去 %GOPATH% 写的src 找,就很容易的把工程的代码包混淆,不容易管理,同时如果要上传整个项目的代码,还要额外去上传src下被引用的包,这就很麻烦了。当然,dep解决的不止这个问题,Golang 也不止dep这个第三方项目管理工具,但是dep听说比较官方。
  4. Dep is a tool for managing dependencies for Go projects
    Usage: "dep [command]"
    Commands:
    init Set up a new Go project, or migrate an existing one
    status Report the status of the project's dependencies
    ensure Ensure a dependency is safely vendored in the project
    version Show the dep version information
    check Check if imports, Gopkg.toml, and Gopkg.lock are in sync
    Examples:
    dep init set up a new project
    dep ensure install the project's dependencies
    dep ensure -update update the locked versions of all dependencies
    dep ensure -add github.com/pkg/errors add a dependency to the project
    Use "dep help [command]" for more information about a command.
  5. 调试go语言出现:exec: "gcc": executable file not found in %PATH%。 意思就是的说系统的PATH 中没有的gcc 的执行命令,我用的是windows,所以的装个系统gcc编译的工具,再将其配置到系统的环境的PATH 中去,安装的链接地址:https://blog.csdn.net/kingmax54212008/article/details/77188836

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

关注微信
1336 次点击
添加一条新回复 (您需要 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传

用户登录

没有账号?注册
(追記) (追記ここまで)

今日阅读排行

    加载中
(追記) (追記ここまで)

一周阅读排行

    加载中

关注我

  • 扫码关注领全套学习资料 关注微信公众号
  • 加入 QQ 群:
    • 192706294(已满)
    • 731990104(已满)
    • 798786647(已满)
    • 729884609(已满)
    • 977810755(已满)
    • 815126783(已满)
    • 812540095(已满)
    • 1006366459(已满)
    • 692541889

  • 关注微信公众号
  • 加入微信群:liuxiaoyan-s,备注入群
  • 也欢迎加入知识星球 Go粉丝们(免费)

给该专栏投稿 写篇新文章

每篇文章有总共有 5 次投稿机会

收入到我管理的专栏 新建专栏