Skip to content
Merged
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
62 changes: 3 additions & 59 deletions apploader/csv-app/csv-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ package csvapp
*/
import "C"
import (
"apploader/pkg/conversion"
"apploader/pkg/file"
"apploader/secret_server"
"apploader/util/file"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"strconv"
"strings"
"syscall"
"text/template"
Expand Down Expand Up @@ -297,7 +296,7 @@ func CreateSevers(ca *TaskInfo) error {
return fmt.Errorf("user env format error")
}
for k, v := range userEnv {
value := Interface2string(v)
value := conversion.Interface2String(v)
envs = append(envs, fmt.Sprintf("%s=%s", k, value))
}
}
Expand Down Expand Up @@ -386,58 +385,3 @@ func startTask(tasks []*TaskInfo) {
}
}
}

func Interface2string(value interface{}) string {
var key string
if value == nil {
return key
}

switch value.(type) {
case float64:
ft := value.(float64)
key = strconv.FormatFloat(ft, 'f', -1, 64)
case float32:
ft := value.(float32)
key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
case int:
it := value.(int)
key = strconv.Itoa(it)
case uint:
it := value.(uint)
key = strconv.Itoa(int(it))
case int8:
it := value.(int8)
key = strconv.Itoa(int(it))
case uint8:
it := value.(uint8)
key = strconv.Itoa(int(it))
case int16:
it := value.(int16)
key = strconv.Itoa(int(it))
case uint16:
it := value.(uint16)
key = strconv.Itoa(int(it))
case int32:
it := value.(int32)
key = strconv.Itoa(int(it))
case uint32:
it := value.(uint32)
key = strconv.Itoa(int(it))
case int64:
it := value.(int64)
key = strconv.FormatInt(it, 10)
case uint64:
it := value.(uint64)
key = strconv.FormatUint(it, 10)
case string:
key = value.(string)
case []byte:
key = string(value.([]byte))
default:
newValue, _ := json.Marshal(value)
key = string(newValue)
}

return key
}
47 changes: 47 additions & 0 deletions apploader/pkg/conversion/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package conversion

import (
"encoding/json"
"strconv"
)

// Interface2String converts interface{} to string
func Interface2String(value interface{}) string {
if value == nil {
return ""
}

switch v := value.(type) {
case float64:
return strconv.FormatFloat(v, 'f', -1, 64)
case float32:
return strconv.FormatFloat(float64(v), 'f', -1, 64)
case int:
return strconv.Itoa(v)
case uint:
return strconv.Itoa(int(v))
case int8:
return strconv.Itoa(int(v))
case uint8:
return strconv.Itoa(int(v))
case int16:
return strconv.Itoa(int(v))
case uint16:
return strconv.Itoa(int(v))
case int32:
return strconv.Itoa(int(v))
case uint32:
return strconv.Itoa(int(v))
case int64:
return strconv.FormatInt(v, 10)
case uint64:
return strconv.FormatUint(v, 10)
case string:
return v
case []byte:
return string(v)
default:
newValue, _ := json.Marshal(value)
return string(newValue)
}
}
17 changes: 4 additions & 13 deletions apploader/util/file/base.go → apploader/pkg/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@ package file

import "os"

// Exists checks if a file or directory exists
func Exists(path string) bool {
_, err := os.Stat(path) //os.Sta
_, err := os.Stat(path)
if err != nil {
if os.IsExist(err) {
return true
}
return false
return os.IsExist(err)
}
return true
}

func IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}

// IsFile checks if a path is a file
func IsFile(path string) bool {
s, err := os.Stat(path)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions apploader/util/const.go

This file was deleted.

70 changes: 0 additions & 70 deletions apploader/util/sys/cmd_actuator.go

This file was deleted.