34 lines
707 B
Go
34 lines
707 B
Go
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)
|
|
}
|