Go language project related stepped pit

Copyright: hard code word, when you reprint remember to tell me https://blog.csdn.net/dxyinme/article/details/90345070

1.

Golang工程调用另一个包的函数的时候,这个函数的首字母一定要是大写!

2.

构建工程之前,当前目录必须被添加到系统环境变量中的GOPATH中。
可以使用go install <packageName>来将这一个package添加到工程根目录的pkg文件夹中
(会生成一个和包名称相同的.a文件)

所以说,构建工程之前,需要先把src里面的所有包都go install 了,然后再对根目录进行go build

3. Test Related

go语言中的测试文件只需要写成XXX_test.go即可
测试的格式如下:
package test

import (
	"testing"
	//加上你要测试的库
)
func TestOk(t *testing.T) {
	//进行测试, 如果有错误就t.Error(“XXXX”);报错
	t.Error("sS")
}

And then perform in the root directory

go test -v ./...

You can run all the tests in the project file ...

4.travis-CI-related configuration

Two days out for a long time travis-CI's yml configuration.
At least I can read ...
Remember before_install inside the GOPATH into the $ HOME / gopath / src / + github repository

Reference: https://docs.travis-ci.com/user/languages/go/

Take a moment to engage in such a basically like this:

language: 
- go

sudo: required

before_install:
- export GOPATH=$HOME/gopath/src/github.com/1171000106/SuitDatabase


script:
- cd src
- go install -a -v ./...
- cd ..
- cd test
- go test -v ./...

5.Golang file operations
I usually use is this
to read the file:

var f, err = os.OpenFile(filename, os.O_RDONLY, 0)

Write file:

f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0755)

You can see the rest of this:
four methods Golang write simple file operations

Guess you like

Origin blog.csdn.net/dxyinme/article/details/90345070