mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-05-25 12:58:38 -05:00
7c3ddfca32
* feat: allow extending the api server * chore: remove internal packages to pkg * chore: update db_gen.go * fix: expose auth * fix: move logger to pkg * fix: don't generate gitignore for prisma client * fix: allow extensions to register their own api spec * feat: expose pool on server config * fix: nil pointer exception on empty opts * fix: run.go file
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package loaderutils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func GetConfigBytes(configFilePath string) ([][]byte, error) {
|
|
configFileBytes := make([][]byte, 0)
|
|
|
|
if fileExists(configFilePath) {
|
|
fileBytes, err := os.ReadFile(configFilePath) // #nosec G304 -- config files are meant to be read from user-supplied directory
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not read config file at path %s: %w", configFilePath, err)
|
|
}
|
|
|
|
configFileBytes = append(configFileBytes, fileBytes)
|
|
}
|
|
|
|
return configFileBytes, nil
|
|
}
|
|
|
|
func GetFileBytes(filename string) ([]byte, error) {
|
|
if fileExists(filename) {
|
|
fileBytes, err := os.ReadFile(filename) // #nosec G304 -- config files are meant to be read from user-supplied directory
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not read config file at path %s: %w", filename, err)
|
|
}
|
|
|
|
return fileBytes, nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("could not read config file at path %s", filename)
|
|
}
|
|
|
|
func fileExists(filename string) bool {
|
|
info, err := os.Stat(filename)
|
|
if err != nil && os.IsNotExist(err) {
|
|
return false
|
|
} else if err != nil {
|
|
return false
|
|
}
|
|
|
|
return !info.IsDir()
|
|
}
|