fix lint issue (#319)

This commit is contained in:
Minghe
2019-10-14 10:20:12 +08:00
committed by GitHub
parent 293481f081
commit 3882f843bf
9 changed files with 32 additions and 26 deletions

View File

@@ -1,4 +1,4 @@
on: push
on: [push, pull_request]
name: ci
jobs:
Test:

View File

@@ -1,5 +1,4 @@
run:
concurrency: 4
deadline: 10m
timeout: 10m
issues-exit-code: 1
@@ -7,21 +6,25 @@ run:
skip-dirs:
- examples
- api/images
- test
# skip-files:
- test/functions
linters:
enable:
- megacheck
- govet
- deadcode
# - gocyclo
- golint
- varcheck
- structcheck
- errcheck
- dupl
- ineffassign
- goimports
- stylecheck
- gosec
- interfacer
- unconvert
enable-all: false
- goconst
- gocyclo
- misspell
- unparam
issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- goconst
- errcheck
- dupl
- gosec

View File

@@ -63,7 +63,7 @@ func (c *Config) Init() error {
}
if err := viper.ReadInConfig(); err != nil {
return fmt.Errorf("Fatal error config file: %s", err)
return fmt.Errorf("fatal error config file: %s", err)
}
return nil
}

View File

@@ -88,10 +88,10 @@ func (d *Docker) PushImage(ctx context.Context, name string) (string, error) {
username := os.Getenv("DOCKER_USERNAME")
password := os.Getenv("DOCKER_PASSWORD")
if username == "" || password == "" {
return "", fmt.Errorf("DOCKER_USERNAME and DOCKER_PASSWORD required for push image to registy")
return "", fmt.Errorf("DOCKER_USERNAME and DOCKER_PASSWORD required for push image to registry")
}
// TODO support private registy, like Azure Container registry
// TODO support private registry, like Azure Container registry
authConfig := dockerTypes.AuthConfig{
Username: username,
Password: password,

View File

@@ -45,7 +45,7 @@ func TestDocker(t *testing.T) {
username := os.Getenv("DOCKER_USERNAME")
password := os.Getenv("DOCKER_PASSWORD")
if username == "" || password == "" {
t.Skip("Skip push image test since DOCKER_USERNAME and DOCKER_PASSWORD not set in enviroment variable")
t.Skip("Skip push image test since DOCKER_USERNAME and DOCKER_PASSWORD not set in environment variable")
}
img, err := cli.PushImage(ctx, name)

View File

@@ -17,6 +17,8 @@ type K8S struct {
*kubernetes.Clientset
}
const namespace = "default"
// Create a k8s cluster client
func Create() (*K8S, error) {
kubeconfig := os.Getenv("KUBECONFIG")
@@ -43,8 +45,6 @@ func (k *K8S) Deploy(
name string,
ports []int32,
) error {
namespace := "default"
dockerClient, err := runtime.CreateClient(ctx)
if err != nil {
return err
@@ -121,7 +121,6 @@ func (k *K8S) Update(ctx context.Context, name string) error {
// Destroy a service
func (k *K8S) Destroy(ctx context.Context, name string) error {
const namespace = "default"
if err := k.DeleteService(namespace, name); err != nil {
return err
}

View File

@@ -14,7 +14,7 @@ type DockerPacker struct {
box packr.Box
}
func isHandler(lang string, name string) bool {
func isHandler(name string) bool {
basename := filepath.Base(name)
nameWithoutExt := strings.TrimSuffix(basename, filepath.Ext(basename))
return nameWithoutExt == "fx" ||
@@ -39,7 +39,7 @@ func (p *DockerPacker) Pack(serviceName string, fn types.ServiceFunctionSource)
}
// if preset's file is handler function of project, replace it with give one
if isHandler(fn.Language, name) {
if isHandler(name) {
files = append(files, types.ProjectSourceFile{
Path: strings.Replace(name, prefix, "", 1),
Body: fn.Source,

View File

@@ -42,8 +42,10 @@ func (l *LocalRunner) Run(script string) ([]byte, error) {
params := strings.Split(script, " ")
var cmd *exec.Cmd
if len(params) > 1 {
// nolint: gosec
cmd = exec.Command(params[0], params[1:]...)
} else {
// nolint: gosec
cmd = exec.Command(params[0])
}
return cmd.CombinedOutput()

View File

@@ -22,6 +22,7 @@ func Download(filepath string, url string) (err error) {
}
defer out.Close()
// nolint: gosec
resp, err := http.Get(url)
if err != nil {
return err
@@ -48,6 +49,7 @@ func Unzip(source string, target string) (err error) {
}
for _, file := range reader.File {
//nolint: gosec
path := filepath.Join(target, file.Name)
if file.FileInfo().IsDir() {
if err := os.MkdirAll(path, file.Mode()); err != nil {
@@ -262,7 +264,7 @@ func PairsToParams(pairs []string) map[string]string {
func OutputJSON(v interface{}) error {
bytes, err := json.MarshalIndent(v, "", "\t")
if err != nil {
return fmt.Errorf("Could marshal %v : %v", v, err)
return fmt.Errorf("could marshal %v : %v", v, err)
}
fmt.Println(string(bytes))