GoLang语言web服务开发准备
本文主要思路是根据一个chitchat项目来玩转go语言(项目来源于goweb编程一书) 实现的web基础开发,以及模板文件加载 路由,数据库操作等功能。
运行效果如下
系统环境:macos
使用到的软件:postgres数据库,navicat 数据库客户端工具,Intellij 编译工具,github demo管理
go语言的学习楼主推荐如下学习地址
https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/directory.md
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/preface.md
Go语言环境安装
安装go的基础编译运行环境 mac brew install go ,或者 也可以直接去官网下载安装包 [官网地址下载] (https://golang.google.cn/dl/) 可根据自己的系统和版本下载对应的安装包
以下这几个环境变量是重点,根据自己下载的go的版本和安装路径进行设置
GOROOT=/usr/local/Cellar/go/1.12.1/libexec
export GOROOT
export GOPATH=/Users/jiangqiaowei/mygo
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN:$GOROOT/bin
GOROOT: go安装目录
GOPATH:go工作目录
(其中包括src bin pkg三个子目录 需要自己手动创建,src 为工程目录需要把go的项目放在这个目录中进行编译,bin为引用库目录新建放那就好, pkg打包生成目录新建放那就好)
GOBIN:go可执行文件目录
PATH:将go可执行文件加入PATH中,使GO命令与我们编写的GO应用可以全局调用,编辑完之后退出保存文件,然后使用
source ~/.bash_profile 使环境变量生效
设置多个path
mac: