初始化
This commit is contained in:
33
services/utils.go
Normal file
33
services/utils.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetOutputPath(inputPath, suffix string) string {
|
||||
ext := filepath.Ext(inputPath)
|
||||
name := strings.TrimSuffix(inputPath, ext)
|
||||
return name + suffix + ext
|
||||
}
|
||||
|
||||
func ChangeExtension(filePath, newExt string) string {
|
||||
ext := filepath.Ext(filePath)
|
||||
name := strings.TrimSuffix(filePath, ext)
|
||||
return name + newExt
|
||||
}
|
||||
|
||||
func GetBaseName(filePath string) string {
|
||||
name := filepath.Base(filePath)
|
||||
ext := filepath.Ext(name)
|
||||
return strings.TrimSuffix(name, ext)
|
||||
}
|
||||
|
||||
func ToJSON(v interface{}) ([]byte, error) {
|
||||
return json.MarshalIndent(v, "", " ")
|
||||
}
|
||||
|
||||
func ParseJSON(data []byte, v interface{}) error {
|
||||
return json.Unmarshal(data, v)
|
||||
}
|
||||
Reference in New Issue
Block a user