Golang 运维脚本

记录编译工具代码 Makefile
替换binary路径使用

BINARY={Path}
GOARCH=amd64

VERSION?=?
BUILD=`date +%FT%T%z`

LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}"

.PHONY: help build linux darwin windows clean version

help:
    @echo "usage: make <option>"
    @echo "options and effects:"
    @echo "    help   : Show help"
    @echo "    build  : Build the binary of this project for current platform"
    @echo "    linux  : Build the linux binary of this project"
    @echo "    darwin : Build the darwin binary of this project"
    @echo "    windows: Build the windows binary of this project"
    @echo "    clean  : Remove binaries"
    @echo "    version: Display Go version"

build:
    @go build ${LDFLAGS} -o ${BINARY}

linux:
    @GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-linux-${GOARCH}

darwin:
    @GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH}

windows:
    @GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH}.exe

clean:
    @rm -f ${BINARY}
    @rm -f ${BINARY}-*

version:
    @go version%

记录上传测试环境工具代码

#!/usr/bin/env bash

make linux
rsync  -avzrC  Go-linux-amd64 config/test.yaml axdict@127.0.0.1:/home/axdict/go/

替换本地ip为远端ip 和 要同步的文件

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容