-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
embed key with ldflags/pause on windows
- Loading branch information
Showing
3 changed files
with
145 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/antonholmquist/jason" | ||
) | ||
|
||
func Test_httpGet(t *testing.T) { | ||
ret := []byte(`{ | ||
"errorCode": "0", | ||
"query": "good", | ||
"translation": [ | ||
"好" | ||
], | ||
"basic": { | ||
"phonetic": "gʊd", | ||
"uk-phonetic": "gʊd", | ||
"us-phonetic": "ɡʊd", | ||
"uk-speech": "XXXX", | ||
"us-speech": "XXXX", | ||
"explains": [ | ||
"好处", | ||
"好的", | ||
"好" | ||
] | ||
}, | ||
"web": [ | ||
{ | ||
"key": "good", | ||
"value": [ | ||
"良好", | ||
"善", | ||
"美好" | ||
] | ||
} | ||
], | ||
"dict": { | ||
"url": "yddict://m.youdao.com/dict?le=eng&q=good" | ||
}, | ||
"webdict": { | ||
"url": "http://m.youdao.com/dict?le=eng&q=good" | ||
}, | ||
"l": "EN2zh-CHS", | ||
"tSpeakUrl": "XXX", | ||
"speakUrl": "XXX" | ||
}`) | ||
obj, _ := jason.NewObjectFromBytes(ret) | ||
type args struct { | ||
url string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *jason.Object | ||
}{ | ||
// TODO: Add test cases. | ||
{"mock", args{"http://www.mocky.io/v2/5d11ba66310000913e08cdcd"}, obj}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := httpGet(tt.args.url); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("httpGet() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_printExplain(t *testing.T) { | ||
ret := []byte(`{ | ||
"errorCode": "0", | ||
"query": "good", | ||
"translation": [ | ||
"好" | ||
], | ||
"basic": { | ||
"phonetic": "gʊd", | ||
"uk-phonetic": "gʊd", | ||
"us-phonetic": "ɡʊd", | ||
"uk-speech": "XXXX", | ||
"us-speech": "XXXX", | ||
"explains": [ | ||
"好处", | ||
"好的", | ||
"好" | ||
] | ||
}, | ||
"web": [ | ||
{ | ||
"key": "good", | ||
"value": [ | ||
"良好", | ||
"善", | ||
"美好" | ||
] | ||
} | ||
], | ||
"dict": { | ||
"url": "yddict://m.youdao.com/dict?le=eng&q=good" | ||
}, | ||
"webdict": { | ||
"url": "http://m.youdao.com/dict?le=eng&q=good" | ||
}, | ||
"l": "EN2zh-CHS", | ||
"tSpeakUrl": "XXX", | ||
"speakUrl": "XXX" | ||
}`) | ||
obj, _ := jason.NewObjectFromBytes(ret) | ||
type args struct { | ||
q string | ||
v *jason.Object | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
// TODO: Add test cases. | ||
{"good", args{"good", obj}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
printExplain(tt.args.q, tt.args.v) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
#!/bin/bash | ||
YDAPPID="" | ||
YDAPPSEC="" | ||
source .ydkey # | ||
|
||
GITVER=$(git rev-parse --short HEAD) | ||
VER=$1 | ||
|
||
if [[ -z $VER ]]; then | ||
VER=$GITVER | ||
fi | ||
|
||
VER=$(git describe --tags || git rev-parse --short HEAD) | ||
LDFLAGS="-s -w -X main.VERSION=$VER -X main.YDAppId=$YDAPPID -X main.YDAppSec=$YDAPPSEC" | ||
|
||
BIN=ydgo | ||
rm -fv ydgo_* | ||
|
||
# for normal unix env | ||
for OS in darwin linux; do | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=$OS go build -o ${BIN}_${OS} -ldflags "-s -w -X main.VERSION=$VER" | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=$OS go build -o ${BIN}_${OS} -ldflags "${LDFLAGS}" | ||
done | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -o ${BIN}_windows.exe -ldflags "-s -w -X main.VERSION=$VER" | ||
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -o ${BIN}_windows.exe -ldflags "${LDFLAGS}" | ||
|