Skip to content

Commit

Permalink
refactor: move main.go back into SRC and attach module to flagmanifes…
Browse files Browse the repository at this point in the history
…t schema

Signed-off-by: Florin-Mihai Anghel <fanghel@google.com>
  • Loading branch information
anghelflorinm committed Sep 30, 2024
1 parent 9b8ddd8 commit 5bdfc10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 130 deletions.
12 changes: 12 additions & 0 deletions docs/schema/v0/flagmanifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package flagmanifest embeds the flag manifest into a code module.
package flagmanifest

import _ "embed"

// Schema contains the embedded flag manifest schema.
//
//go:embed flag_manifest.json
var Schema string

// SchemaPath proviees the current path and version of flag manifest.
const SchemaPath = "codegen/docs/schema/v0/flag_manifest.json"
120 changes: 0 additions & 120 deletions main.go

This file was deleted.

9 changes: 4 additions & 5 deletions src/example_go/experimentflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
)

var client *openfeature.Client = nil

// This is a flag.
var MyOpenFeatureFlag = struct {
Value providers.BooleanProvider
Value providers.BooleanProvider
}{
Value: func(ctx context.Context) (bool, error) {
return client.BooleanValue(ctx, "myOpenFeatureFlag", false, openfeature.EvaluationContext{})
},
Value: func(ctx context.Context) (bool, error) {
return client.BooleanValue(ctx, "myOpenFeatureFlag", false, openfeature.EvaluationContext{})
},
}

func init() {
Expand Down
9 changes: 4 additions & 5 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
generator "codegen/generators"
"codegen/generators/golang"
flagmanifest "codegen/docs/schema/v0"
generator "codegen/src/generators"
"codegen/src/generators/golang"
_ "embed"
"encoding/json"
"flag"
Expand All @@ -15,8 +16,6 @@ import (
jsonschema "github.com/santhosh-tekuri/jsonschema/v5"
)

const flagManifestSchema = "../docs/schema/v0/flag_manifest.json"

var flagManifestPath = flag.String("flag_manifest_path", "", "Path to the flag manifest.")
var moduleName = flag.String("module_name", "", "Name of the module to be generated.")
var outputPath = flag.String("output_path", "", "Output path for the codegen")
Expand Down Expand Up @@ -49,7 +48,7 @@ func unmarshalFlagManifest(data []byte, supportedFlagTypes map[generator.FlagTyp
return nil, fmt.Errorf("error unmarshalling JSON: %v", err)
}

sch, err := jsonschema.Compile(flagManifestSchema)
sch, err := jsonschema.CompileString(flagmanifest.SchemaPath, flagmanifest.Schema)
if err != nil {
return nil, fmt.Errorf("error compiling JSON schema: %v", err)
}
Expand Down

0 comments on commit 5bdfc10

Please sign in to comment.