Skip to content

Commit

Permalink
fix: fix log
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Jun 23, 2023
1 parent 4b75026 commit 4290f09
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
7 changes: 4 additions & 3 deletions api/device_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/ngaut/log"
"log"

"github.com/urfave/cli/v2"
)

Expand All @@ -23,7 +24,7 @@ func CreateDevice(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
_, result := post(maps, host, DEVICE_API_NAME)
fmt.Println(result)
Expand All @@ -37,7 +38,7 @@ func UpdateDevice(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
result := put(host, DEVICE_API_NAME, maps)
fmt.Println(result)
Expand Down
7 changes: 4 additions & 3 deletions api/inend_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/ngaut/log"
"log"

"github.com/urfave/cli/v2"
)

Expand All @@ -23,7 +24,7 @@ func CreateInend(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
_, result := post(maps, host, INEND_API_NAME)
fmt.Println(result)
Expand All @@ -37,7 +38,7 @@ func UpdateInEnd(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
result := put(host, INEND_API_NAME, maps)
fmt.Println(result)
Expand Down
7 changes: 4 additions & 3 deletions api/outend_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/ngaut/log"
"log"

"github.com/urfave/cli/v2"
)

Expand All @@ -23,7 +24,7 @@ func CreateOutends(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
_, result := post(maps, host, OUTEND_API_NAME)
fmt.Println(result)
Expand All @@ -37,7 +38,7 @@ func UpdateOutEnd(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
result := put(host, OUTEND_API_NAME, maps)
fmt.Println(result)
Expand Down
7 changes: 4 additions & 3 deletions api/rule_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"

"github.com/ngaut/log"
"log"

"github.com/urfave/cli/v2"
)

Expand All @@ -16,7 +17,7 @@ func CreateRule(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Println(config, err)
} else {
_, result := post(maps, host, OUTEND_API_NAME)
fmt.Println(result)
Expand All @@ -37,7 +38,7 @@ func UpdateRule(c *cli.Context) error {
maps := map[string]interface{}{}
err := json.Unmarshal([]byte(config), &maps)
if err != nil {
log.Error(config, err)
log.Panicln(config, err)
} else {
result := put(host, OUTEND_API_NAME, maps)
fmt.Println(result)
Expand Down
16 changes: 8 additions & 8 deletions api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"net/http"

"github.com/ngaut/log"
"log"
)

// HTTP Post
Expand Down Expand Up @@ -35,13 +35,13 @@ func get(host string, api string) string {
// Get list
r, errs := http.Get(("http://" + host + ":2580/api/v1/" + api))
if errs != nil {
log.Error(errs)
log.Println(errs)
return ""
}
defer r.Body.Close()
body, errs2 := io.ReadAll(r.Body)
if errs2 != nil {
log.Error(errs2)
log.Println(errs2)
return ""
}
return string(body)
Expand All @@ -55,12 +55,12 @@ func delete(host string, api string, param string) string {
nil,
)
if err0 != nil {
log.Error(err0)
log.Println(err0)
return ""
}
response, err1 := http.DefaultClient.Do(req)
if err1 != nil {
log.Error(err1)
log.Println(err1)
return ""
}
defer response.Body.Close()
Expand All @@ -83,18 +83,18 @@ func put(host string, api string, data map[string]interface{}) string {
bytes.NewBuffer(p),
)
if err0 != nil {
log.Error(err0)
log.Println(err0)
return ""
}
response, err1 := http.DefaultClient.Do(req)
if err1 != nil {
log.Error(err1)
log.Println(err1)
return ""
}
defer response.Body.Close()
body, errs5 := io.ReadAll(response.Body)
if errs5 != nil {
log.Error(errs5)
log.Println(errs5)
return ""
}

Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ module rulexc

go 1.17

require (
github.com/ngaut/log v0.0.0-20221012222132-f3329cba28a5
github.com/urfave/cli/v2 v2.25.7
)
require github.com/urfave/cli/v2 v2.25.7

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
)
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"os"
"rulexc/api"

"github.com/ngaut/log"
"log"

"github.com/urfave/cli/v2"
)

Expand Down

0 comments on commit 4290f09

Please sign in to comment.