-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from kanmu/support_overrides_file
Support overrides file
- Loading branch information
Showing
4 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package definition | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kanmu/demitas2/utils" | ||
"github.com/valyala/fastjson" | ||
) | ||
|
||
type Overrides struct { | ||
Content []byte | ||
} | ||
|
||
func newOoverrides(path string) (*Overrides, error) { | ||
_, err := os.Stat(path) | ||
|
||
if err != nil { | ||
return &Overrides{}, nil | ||
} | ||
|
||
content, err := utils.EvaluateJsonnet(path) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse overrides file: %w: %s", err, path) | ||
} | ||
|
||
overrides := &Overrides{ | ||
Content: content, | ||
} | ||
|
||
return overrides, nil | ||
} | ||
|
||
func (overrides *Overrides) get(key string) string { | ||
var p fastjson.Parser | ||
content, _ := p.ParseBytes(overrides.Content) | ||
v := content.Get(key) | ||
|
||
if v != nil { | ||
return v.String() | ||
} else { | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters