Golang / InteliJ / VScode / gitlab
Menu
Golang を isntall
brew install go
InteliJ
JetBrain の学生アカウントを取得して、Ultimate を down load する
InteliJ に Golang の plugin を入れる
環境変数
zshrc などに設定する
export GO111MODULE=on
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=/Users/kono/src/go
VSCode
Golang の plugin を入れる
Project を作成する
go を選択
FileWrite というプロジェクトを作る
Test を作る
InteliJ で go file を選択し、control click から generate -> test for file で作成する。
gitlab に登録する
group OS/2021 の下の e195788-filewrite という名前で Project を作る
mkdir -p ~/src/go/src/gitlab.ie.u-ryukyu.ac.jp/os/2021/kono-filewrite2 cd ~/src/go/src/gitlab.ie.u-ryukyu.ac.jp:os/2021 git clone git@gitlab.ie.u-ryukyu.ac.jp:os/2021/kono-filewrite2.gitで、たぶん、
go mod init gitlab.ie.u-ryukyu.ac.jp/os/2021/kono-filewrite-3これで go.mod ができる
go を走らせる
main.go をそこに作る
package main
import (
"fmt"
"gitlab.ie.u-ryukyu.ac.jp/os/2021/kono-filewrite2/fileWrite"
)
func main() {
fmt.Println("Hello, World!")
fmt.Println( fileWrite.Hello("kono"))
}
fileWrite/fileWrite.go を作る
package fileWrite
import "fmt"
// Hello returns a greeting for the named person.
func Hello(name string) string {
// Return a greeting that embeds the name in a message.
message := fmt.Sprintf("Hi, %v. Welcome!", name)
return message
}
で、
go run main.goする。
IntelJ と VSCode からも動作させる。
gitに転送する
git add go.mod main.go fileWrite/fileWrite.go git commit -a git push
gitlab CI/CD
今年は gitlab の CI/CD を使います。
Project に .gitlab-ci.yml を以下のようにして、git push します。
# Setup a cache to cache job parts between jobs to ensure faster builds
cache:
key: "$CI_JOB_NAME"
untracked: true
paths:
- $HOME/.cargo/
- target/
# Define a yaml template for running a build and then running your tests
.cargo_test_template: &cargo_test
script:
- rustc --version && cargo --version
- cargo build
- cargo test --verbose
test:stable:
image: "rustdocker/rust:stable"
<<: *cargo_test
成功したのと失敗した version の consle のURLを含めて提出します。
なので、以下は関係ない。歴史的な関係で残してはおきます。