function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}
if docker_tag_exists library/nginx 1.7.5; then
echo exist
else
echo not exists
fi
func interToInt64(inp interface{}) (int64, error) {
switch v := inp.(type) {
case int:
return int64(v), nil
case int8:
return int64(v), nil
case int16:
return int64(v), nil
case int32:
return int64(v), nil
case int64:
return v, nil
case uint:
return int64(v), nil
case uint8:
return int64(v), nil
case uint16:
return int64(v), nil
case uint32:
return int64(v), nil
case uint64:
return int64(v), nil
case string:
return strconv.ParseInt(v, 10, 64)
default:
return 0, fmt.Errorf("unsupported type %T", inp)
}
}
func main() {
router := gin.Default()
router.Static("/static", "./static")
router.StaticFile("/index.htm", "./static/index.htm")
router.Run(":8080")
}
go mod init your/module/path
func main {
log := logrus.New()
// Передача логера через параметр в функции
pkg1MyFunc(log, "data1", "data2")
// Структура с конструктором
s := NewMyStruct(log, "data")
s.Do("params")
}
// Передача логера через параметр в функции
func pkg1MyFunc(log logrus.FieldLogger, data1, data2 string) {
log.Info(data1, data2)
}
// Структура с конструктором
type MyStruct struct {
log logrus.FieldLogger
data string
}
func NewMyStruct(log logrus.FieldLogger, data string) *MyStruct {
return &MyStruct{log: log, data: data}
}
func (s *MyStruct) Do(params string) {
s.log.Info(s.data, params)
}
type MyStruct struct {
log logrus.FieldLogger
store storage.Store
data string
}
func NewMyStruct(log logrus.FieldLogger, store storage.Store, data string) *MyStruct {
return &MyStruct{log: log, data: data, store: store}
}
func (s *MyStruct) Do(params string) {
s.log.Info(s.data, params)
s.store.AddParams(params)
}
stages:
- deploy
deploy_master:
image: alpine
stage: deploy
script:
- apk update && apk upgrade
- apk add openssh bash rsync
- echo "====== Deploy to production server ======"
- echo "====== Add target servers secret key ======"
- mkdir ~/.ssh
- echo $TARGET_SERVER_SECRET_KEY > ~/.ssh/id_rsa
- chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
- echo "====== Test ssh connection ======"
- ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -T "root@target_server"
- echo "====== Sync local and remote directory ======"
- rsync -av -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --delete ./ "root@target_server:/home/webserver/"
only:
- master
package main
import (
"fmt"
)
func main() {
arr := [5]float64{1, 2, 3, 4, 5}
i := 3
x := append([]float64{}, arr[:i]...)
x[2] = 42
fmt.Println(x)
fmt.Println(arr)
}
вообще они могут сделать изоморфное приложение с SSR
go test -bench .
и всё заработает.$ go test -bench .
goos: darwin
goarch: amd64
pkg: api
BenchmarkAwesomeToJSON-8 3000000 470 ns/op
PASS
ok api 1.895s
go test -bench . test_test.go test.go
, но проще без них.func BenchmarkAwesomeToJSON(b *testing.B) {
awesome := NewAwesome("123456789", "Total awesomeness", 9.99, true)
b.ResetTimer()
for i := 0; i < b.N; i++ {
awesome.ToJSON()
}
}