Skip to content
This repository was archived by the owner on Jan 10, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package edgecli
import (
"bytes"
"encoding/json"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"net/http"

log "github.com/sirupsen/logrus"
)

type AuthResp struct {
Expand Down Expand Up @@ -62,14 +62,14 @@ func (s *AuthService) Login(opt *AuthOption) (*AuthResp, error) {
authJson, _ := json.Marshal(resp.(*SuccessResponse).Data)
auth := AuthResp{}
if err := json.Unmarshal(authJson, &auth); err != nil {
return nil, errors.New(fmt.Sprintf("Fail to unmarshal response's data ,err is %+v", err))
return nil, fmt.Errorf("Fail to unmarshal response's data ,err is %+v", err)
}
log.Debugf("auth token is %+v", auth)
return &auth, nil
case *ErrorResponse:
return nil, errors.New(fmt.Sprintf("Fail to login, error message: %s", resp.(*ErrorResponse).Message))
return nil, fmt.Errorf("Fail to login, error message: %s", resp.(*ErrorResponse).Message)
default:
return nil, errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return nil, fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}
}

Expand All @@ -90,13 +90,13 @@ func (s *AuthService) Refresh(opt *RefreshTokenOption) (*AuthResp, error) {
authJson, _ := json.Marshal(resp.(*SuccessResponse).Data)
auth := AuthResp{}
if err := json.Unmarshal(authJson, &auth); err != nil {
return nil, errors.New(fmt.Sprintf("Fail to unmarshal response's data ,err is %+v", err))
return nil, fmt.Errorf("Fail to unmarshal response's data ,err is %+v", err)
}
log.Debugf("auth token is %+v", auth)
return &auth, nil
case *ErrorResponse:
return nil, errors.New(fmt.Sprintf("Fail to login, error message: %s", resp.(*ErrorResponse).Message))
return nil, fmt.Errorf("Fail to login, error message: %s", resp.(*ErrorResponse).Message)
default:
return nil, errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return nil, fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}
}
3 changes: 2 additions & 1 deletion cmd/edgecli/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cmd

import (
"fmt"
"strings"

"github.com/manifoldco/promptui"
edge "github.com/omniedgeio/omniedge-cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"strings"
)

var joinCmd = &cobra.Command{
Expand Down
5 changes: 3 additions & 2 deletions cmd/edgecli/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"fmt"
"os"
"strings"

edge "github.com/omniedgeio/omniedge-cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/crypto/ssh/terminal"
"os"
"strings"
)

var loginCmd = &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions cmd/edgecli/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

edge "github.com/omniedgeio/omniedge-cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
6 changes: 4 additions & 2 deletions cmd/edgecli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package cmd
import (
"errors"
"fmt"

"strings"

edge "github.com/omniedgeio/omniedge-cli"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"strings"
)

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -79,7 +81,7 @@ func loadScanResult() error {
viper.SetConfigFile(handledScanResultFile)
viper.SetConfigType("json")
if err = viper.ReadInConfig(); err != nil {
return errors.New(fmt.Sprintf("fail to read omniedge scan result, please scan first."))
return errors.New("fail to read omniedge scan result, please scan first.")
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions cmd/edgecli/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/mitchellh/mapstructure"
edgecli "github.com/omniedgeio/omniedge-cli"
log "github.com/sirupsen/logrus"
Expand Down
5 changes: 3 additions & 2 deletions cmd/edgecli/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"os"
"os/user"

edgecli "github.com/omniedgeio/omniedge-cli"
rootCmd "github.com/omniedgeio/omniedge-cli/cmd/edgecli/cmd"
log "github.com/sirupsen/logrus"
"os"
"os/user"
)

var Env string
Expand Down
7 changes: 3 additions & 4 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package edgecli
import (
"bytes"
"encoding/json"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"net/http"
Expand Down Expand Up @@ -40,13 +39,13 @@ func (s *RegisterService) Register(opt *RegisterOption) (*DeviceResponse, error)
deviceJson, _ := json.Marshal(resp.(*SuccessResponse).Data)
device := DeviceResponse{}
if err := json.Unmarshal(deviceJson, &device); err != nil {
return nil, errors.New(fmt.Sprintf("Fail to unmarshal response's data ,err is %+v", err))
return nil, fmt.Errorf("Fail to unmarshal response's data ,err is %+v", err)
}
log.Debugf("Registerdevice result is %+v", device)
return &device, nil
case *ErrorResponse:
return nil, errors.New(fmt.Sprintf("Fail to register device, error message: %s", resp.(*ErrorResponse).Message))
return nil, fmt.Errorf("Fail to register device, error message: %s", resp.(*ErrorResponse).Message)
default:
return nil, errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return nil, fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}
}
2 changes: 1 addition & 1 deletion internal/n2n
Submodule n2n updated from aaf84a to d33028
17 changes: 8 additions & 9 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/panta/machineid"
log "github.com/sirupsen/logrus"
"net"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"

"github.com/google/uuid"
"github.com/panta/machineid"
log "github.com/sirupsen/logrus"
)

var Env string
Expand Down Expand Up @@ -102,16 +103,16 @@ func getMacAddress() (string, error) {
func RevealHardwareUUID() (string, error) {
id, err := machineid.ID()
if err != nil {
return "", errors.New(fmt.Sprintf("Fail to generate hardware id, err is %+v", err))
return "", fmt.Errorf("Fail to generate hardware id, err is %+v", err)
}
id = strings.ToLower(strings.Replace(id, "-", "", -1))
idBytes, err := hex.DecodeString(id)
if err != nil {
return "", errors.New(fmt.Sprintf("Fail to generate hardware id, err is %+v", err))
return "", fmt.Errorf("Fail to generate hardware id, err is %+v", err)
}
hardwareUUID, err := uuid.FromBytes(idBytes)
if err != nil {
return "", errors.New(fmt.Sprintf("Fail to generate hardware id, err is %+v", err))
return "", fmt.Errorf("Fail to generate hardware id, err is %+v", err)
}
return hardwareUUID.String(), nil
}
Expand All @@ -122,12 +123,10 @@ func RevealHostName() string {
return ""
}
return name

}

func RevealOS() string {
return runtime.GOOS

}

func GenerateRandomMac() (string, error) {
Expand All @@ -154,7 +153,7 @@ func GetCurrentDeviceNetStatus(cidrStr string) (*DeviceNet, error) {
}
cidr, err := ParseCIDR(cidrStr)
if err != nil {
return nil, errors.New(fmt.Sprintf("Fail to parse cidr, %+v", err))
return nil, fmt.Errorf("Fail to parse cidr, %+v", err)
}
var ip, mac string
for _, netInterface := range netInterfaces {
Expand Down
20 changes: 10 additions & 10 deletions virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package edgecli
import (
"bytes"
"encoding/json"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"net/http"

log "github.com/sirupsen/logrus"
)

type VirtualNetwork struct {
Expand Down Expand Up @@ -57,13 +57,13 @@ func (s *VirtualNetworkService) List() ([]VirtualNetworkResponse, error) {
vnJson, _ := json.Marshal(resp.(*SuccessResponse).Data)
var vnResp []VirtualNetworkResponse
if err := json.Unmarshal(vnJson, &vnResp); err != nil {
return nil, errors.New(fmt.Sprintf("Fail to unmarshal response's data ,err is %+v", err))
return nil, fmt.Errorf("Fail to unmarshal response's data ,err is %+v", err)
}
return vnResp, nil
case *ErrorResponse:
return nil, errors.New(fmt.Sprintf("Fail to list user's virtual network, error message: %s", resp.(*ErrorResponse).Message))
return nil, fmt.Errorf("Fail to list user's virtual network, error message: %s", resp.(*ErrorResponse).Message)
default:
return nil, errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return nil, fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}

}
Expand All @@ -80,13 +80,13 @@ func (s *VirtualNetworkService) Join(opt *JoinOption) (*JoinVirtualNetworkRespon
joinVNJson, _ := json.Marshal(resp.(*SuccessResponse).Data)
joinVNResp := JoinVirtualNetworkResponse{}
if err := json.Unmarshal(joinVNJson, &joinVNResp); err != nil {
return nil, errors.New(fmt.Sprintf("Fail to unmarshal response's data ,err is %+v", err))
return nil, fmt.Errorf("Fail to unmarshal response's data ,err is %+v", err)
}
return &joinVNResp, nil
case *ErrorResponse:
return nil, errors.New(fmt.Sprintf("Fail to join, error message: %s", resp.(*ErrorResponse).Message))
return nil, fmt.Errorf("Fail to join, error message: %s", resp.(*ErrorResponse).Message)
default:
return nil, errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return nil, fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}
}

Expand Down Expand Up @@ -119,8 +119,8 @@ func (s *VirtualNetworkService) Upload(opt *UploadOption) error {
case *SuccessResponse:
return nil
case *ErrorResponse:
return errors.New(fmt.Sprintf("Fail to upload, error message: %s", resp.(*ErrorResponse).Message))
return fmt.Errorf("Fail to upload, error message: %s", resp.(*ErrorResponse).Message)
default:
return errors.New(fmt.Sprint("This client has some unpredictable problems, please contact the omniedge team."))
return fmt.Errorf("This client has some unpredictable problems, please contact the omniedge team.")
}
}