-
Notifications
You must be signed in to change notification settings - Fork 9
/
jsonparser.go
28 lines (22 loc) · 988 Bytes
/
jsonparser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package helpers
import (
"context"
"google.golang.org/protobuf/proto"
"namespacelabs.dev/foundation/internal/frontend/fncue"
"namespacelabs.dev/foundation/internal/parsing"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
type SimpleJsonParser[V proto.Message] struct {
// Not "Url" to avoid a collision with the "Url" method.
SyntaxUrl string
SyntaxShortcut string
}
func (p *SimpleJsonParser[V]) Url() string { return p.SyntaxUrl }
func (p *SimpleJsonParser[V]) Shortcut() string { return p.SyntaxShortcut }
func (p *SimpleJsonParser[V]) Parse(ctx context.Context, env *schema.Environment, pl parsing.EarlyPackageLoader, loc pkggraph.Location, v *fncue.CueV) (proto.Message, error) {
return fncue.DecodeToTypedProtoMessage[V](v)
}