Skip to content

Commit cb650f6

Browse files
feat: create pkg package and remove unused code (#19)
1 parent 454ac1d commit cb650f6

File tree

5 files changed

+54
-149
lines changed

5 files changed

+54
-149
lines changed

apploader/csv-app/csv-app.go

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ package csvapp
77
*/
88
import "C"
99
import (
10+
"apploader/pkg/conversion"
11+
"apploader/pkg/file"
1012
"apploader/secret_server"
11-
"apploader/util/file"
12-
"encoding/json"
1313
"fmt"
1414
"io/ioutil"
1515
"log"
1616
"os"
1717
"os/exec"
1818
"path"
19-
"strconv"
2019
"strings"
2120
"syscall"
2221
"text/template"
@@ -297,7 +296,7 @@ func CreateSevers(ca *TaskInfo) error {
297296
return fmt.Errorf("user env format error")
298297
}
299298
for k, v := range userEnv {
300-
value := Interface2string(v)
299+
value := conversion.Interface2String(v)
301300
envs = append(envs, fmt.Sprintf("%s=%s", k, value))
302301
}
303302
}
@@ -386,58 +385,3 @@ func startTask(tasks []*TaskInfo) {
386385
}
387386
}
388387
}
389-
390-
func Interface2string(value interface{}) string {
391-
var key string
392-
if value == nil {
393-
return key
394-
}
395-
396-
switch value.(type) {
397-
case float64:
398-
ft := value.(float64)
399-
key = strconv.FormatFloat(ft, 'f', -1, 64)
400-
case float32:
401-
ft := value.(float32)
402-
key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
403-
case int:
404-
it := value.(int)
405-
key = strconv.Itoa(it)
406-
case uint:
407-
it := value.(uint)
408-
key = strconv.Itoa(int(it))
409-
case int8:
410-
it := value.(int8)
411-
key = strconv.Itoa(int(it))
412-
case uint8:
413-
it := value.(uint8)
414-
key = strconv.Itoa(int(it))
415-
case int16:
416-
it := value.(int16)
417-
key = strconv.Itoa(int(it))
418-
case uint16:
419-
it := value.(uint16)
420-
key = strconv.Itoa(int(it))
421-
case int32:
422-
it := value.(int32)
423-
key = strconv.Itoa(int(it))
424-
case uint32:
425-
it := value.(uint32)
426-
key = strconv.Itoa(int(it))
427-
case int64:
428-
it := value.(int64)
429-
key = strconv.FormatInt(it, 10)
430-
case uint64:
431-
it := value.(uint64)
432-
key = strconv.FormatUint(it, 10)
433-
case string:
434-
key = value.(string)
435-
case []byte:
436-
key = string(value.([]byte))
437-
default:
438-
newValue, _ := json.Marshal(value)
439-
key = string(newValue)
440-
}
441-
442-
return key
443-
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package conversion
2+
3+
import (
4+
"encoding/json"
5+
"strconv"
6+
)
7+
8+
// Interface2String converts interface{} to string
9+
func Interface2String(value interface{}) string {
10+
if value == nil {
11+
return ""
12+
}
13+
14+
switch v := value.(type) {
15+
case float64:
16+
return strconv.FormatFloat(v, 'f', -1, 64)
17+
case float32:
18+
return strconv.FormatFloat(float64(v), 'f', -1, 64)
19+
case int:
20+
return strconv.Itoa(v)
21+
case uint:
22+
return strconv.Itoa(int(v))
23+
case int8:
24+
return strconv.Itoa(int(v))
25+
case uint8:
26+
return strconv.Itoa(int(v))
27+
case int16:
28+
return strconv.Itoa(int(v))
29+
case uint16:
30+
return strconv.Itoa(int(v))
31+
case int32:
32+
return strconv.Itoa(int(v))
33+
case uint32:
34+
return strconv.Itoa(int(v))
35+
case int64:
36+
return strconv.FormatInt(v, 10)
37+
case uint64:
38+
return strconv.FormatUint(v, 10)
39+
case string:
40+
return v
41+
case []byte:
42+
return string(v)
43+
default:
44+
newValue, _ := json.Marshal(value)
45+
return string(newValue)
46+
}
47+
}
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@ package file
22

33
import "os"
44

5+
// Exists checks if a file or directory exists
56
func Exists(path string) bool {
6-
_, err := os.Stat(path) //os.Sta
7+
_, err := os.Stat(path)
78
if err != nil {
8-
if os.IsExist(err) {
9-
return true
10-
}
11-
return false
9+
return os.IsExist(err)
1210
}
1311
return true
1412
}
1513

16-
func IsDir(path string) bool {
17-
s, err := os.Stat(path)
18-
if err != nil {
19-
return false
20-
}
21-
return s.IsDir()
22-
}
23-
14+
// IsFile checks if a path is a file
2415
func IsFile(path string) bool {
2516
s, err := os.Stat(path)
2617
if err != nil {

apploader/util/const.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

apploader/util/sys/cmd_actuator.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)