refactor: move gateway package to app directory

This commit is contained in:
Prad Nukala
2024-12-09 18:34:38 -05:00
parent 67432d3fdf
commit f250082fff
32 changed files with 13 additions and 13 deletions
+45
View File
@@ -0,0 +1,45 @@
package config
import (
"context"
"github.com/apple/pkl-go/pkl"
)
// LoadFromBytes loads the environment from the given bytes
func LoadFromBytes(data []byte) (Env, error) {
text := string(data)
return LoadFromString(text)
}
// LoadFromString loads the environment from the given string
func LoadFromString(text string) (Env, error) {
evaluator, err := pkl.NewEvaluator(context.Background(), pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err := Load(context.Background(), evaluator, pkl.TextSource(text))
return ret, err
}
// LoadFromURL loads the environment from the given URL
func LoadFromURL(url string) (Env, error) {
evaluator, err := pkl.NewEvaluator(context.Background(), pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err := Load(context.Background(), evaluator, pkl.UriSource(url))
return ret, err
}