Golang 运维脚本

2018-02-03 10:25:44来源:https://www.jianshu.com/p/30379df1554a作者:无言糖人点击

分享

记录编译工具代码 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 和 要同步的文件





微信扫一扫

第七城市微信公众平台