Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.Python
*.crt
.cache
vendor
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- repo: https://github.com/dnephin/pre-commit-golang
sha: e4693a4c282b4fc878eda172a929f7a6508e7d16
hooks:
- id: go-fmt
files: \.go$
- id: go-lint
files: \.go$
20 changes: 20 additions & 0 deletions .tools/check_style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
function abort(){
echo "Your change doesn't follow PaddleCloud's code style." 1>&2
echo "Please use pre-commit to reformat your code and git push again." 1>&2
exit 1
}

trap 'abort' 0
set -e

cd $TRAVIS_BUILD_DIR
export PATH=/usr/bin:$PATH
pre-commit install
pre-commit --version

if ! pre-commit ; then
git diff --exit-code
fi

trap : 0
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ matrix:
include:
- language: go
go: 1.8.x
script: bash .tools/gen_config.sh && cd go && go test ./...
sudo: required
before_script:
- eval "$(GIMME_GO_VERSION=1.8.3 gimme)"
- go get -u github.com/golang/lint/golint
- curl https://glide.sh/get | bash
- sudo pip install pre-commit
script:
- |
bash .tools/check_style.sh
RESULT=$?; if [ $RESULT -eq 0 ]; then true; else false; fi;
- bash .tools/gen_config.sh && cd go && glide install && go test $(glide novendor)
- language: python
python: 2.7
sudo: required
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/pfsserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
func main() {
port := flag.Int("port", 8080, "port of server")
ip := flag.String("ip", "0.0.0.0", "ip of server")
tokenUri := flag.String("tokenuri", "http://cloud.paddlepaddle.org", "uri of token server")
tokenURI := flag.String("tokenuri", "http://cloud.paddlepaddle.org", "uri of token server")
flag.Parse()

router := pfsserver.NewRouter()
addr := fmt.Sprintf("%s:%d", *ip, *port)
pfsserver.TokenUri = *tokenUri
pfsserver.TokenURI = *tokenURI

log.Infof("server on:%s and tokenuri:%s\n", addr, *tokenUri)
log.Infof("server on:%s and tokenuri:%s\n", addr, *tokenURI)
log.Fatal(http.ListenAndServe(addr, router))
}
1 change: 1 addition & 0 deletions go/filemanager/pfsmodules/chunkmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
defaultMinChunkSize = 4 * 1024
)
const (
// ChunkMetaCmdName is the name of GetChunkMeta command.
ChunkMetaCmdName = "GetChunkMeta"
)

Expand Down
2 changes: 1 addition & 1 deletion go/filemanager/pfsmodules/chunkmeta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetDiffMeta(t *testing.T) {
t.Error(len(diff))
}

for i, _ := range diff {
for i := range diff {
if diff[i] != src[i] {
t.Error(i)
}
Expand Down
1 change: 1 addition & 0 deletions go/filemanager/pfsmodules/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
)

const (
// TouchCmdName is the name of touch command.
TouchCmdName = "touch"
)

Expand Down
5 changes: 3 additions & 2 deletions go/filemanager/pfsserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type response struct {
Results interface{} `json:"results"`
}

var TokenUri = ""
// TokenURI is the address of token server
var TokenURI = ""

func getUserName(uri string, token string) (string, error) {
authHeader := make(map[string]string)
Expand Down Expand Up @@ -51,7 +52,7 @@ func getUserName(uri string, token string) (string, error) {
func cmdHandler(w http.ResponseWriter, req string, cmd pfsmod.Command, header http.Header) {
resp := response{}

user, err := getUserName(TokenUri+"/api/v1/token2user/", header.Get("Authorization"))
user, err := getUserName(TokenURI+"/api/v1/token2user/", header.Get("Authorization"))
if err != nil {
resp.Err = "get username error:" + err.Error()
writeJSONResponse(w, req, http.StatusOK, resp)
Expand Down
1 change: 1 addition & 0 deletions go/filemanager/pfsserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Route struct {
HandlerFunc http.HandlerFunc
}

// Routes is the a Route array
type Routes []Route

var routes = Routes{
Expand Down
16 changes: 16 additions & 0 deletions go/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions go/glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package: github.com/PaddlePaddle/cloud/go
import:
- package: github.com/bitly/go-simplejson
version: ^0.5.0
- package: github.com/golang/glog
- package: github.com/google/subcommands
- package: github.com/gorilla/mux
version: ^1.4.0
- package: gopkg.in/yaml.v2
2 changes: 2 additions & 0 deletions go/paddlecloud/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (r *RegistryCmd) Delete() error {
}
return nil
}

// Execute runs RegistryCmd command.
func (r *RegistryCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
if r.SecretName == "" || r.Username == "" || r.Password == "" || r.Server == "" {
f.Usage()
Expand Down