From 18674ba01164d04d43af19df9abfa65765ceb9c4 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Mon, 16 Jan 2017 17:03:38 +0800 Subject: [PATCH] add goreleaser --- .travis.yml | 5 +++++ README.md | 1 + goreleaser.yml | 12 ++++++++++++ main.go | 20 ++++++++++++++++++-- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .travis.yml create mode 100644 goreleaser.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8d908b0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: go +go: + - 1.7.x +after_success: + test -n "$TRAVIS_TAG" && curl -s https://raw.githubusercontent.com/goreleaser/get/master/latest | bash diff --git a/README.md b/README.md index eb2a473..04bd872 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # wdaproxy +[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser) WebDriverAgent Proxy Only can work in Mac diff --git a/goreleaser.yml b/goreleaser.yml new file mode 100644 index 0000000..905ac0f --- /dev/null +++ b/goreleaser.yml @@ -0,0 +1,12 @@ +# Build customization +build: + main: ./main.go + ldflags: -s -w + gogs: + - darwin + - linux + goarch: + - amd64 + files: + - README.md + - LICENSE diff --git a/main.go b/main.go index 2594cc7..c52901c 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,30 @@ package main import ( + "flag" "log" "net/http" "net/http/httputil" "net/url" "os/exec" + "strconv" +) + +var ( + version = "develop" + lisPort = 8100 ) func main() { + showVer := flag.Bool("v", false, "Print version") + flag.IntVar(&lisPort, "p", 8100, "Proxy listen port") + flag.Parse() + + if *showVer { + println(version) + return + } + log.Println("program start......") errC := make(chan error) @@ -17,11 +33,11 @@ func main() { targetURL, _ := url.Parse("http://127.0.0.1:8200") httpProxy := httputil.NewSingleHostReverseProxy(targetURL) http.Handle("/", httpProxy) - errC <- http.ListenAndServe(":8100", nil) + errC <- http.ListenAndServe(":"+strconv.Itoa(lisPort), nil) }() go func() { log.Println("launch iproxy") - c := exec.Command("iproxy", "8200", "8100") + c := exec.Command("iproxy", "8200", strconv.Itoa(lisPort)) errC <- c.Run() }()