This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
140 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
// BuildVariables will be passed to a Golang's ldflags for variable injection. | ||
type BuildVariables map[string]Resolver | ||
|
||
// BuildVariablesBuilder for a build variables. | ||
type BuildVariablesBuilder interface { | ||
// Add a key/value pair. | ||
Add(key string, resolver Resolver) BuildVariablesBuilder | ||
// ConditionallyAdd a key/value pair if cnd is true. | ||
ConditionallyAdd(cnd func() bool, key string, resolver Resolver) BuildVariablesBuilder | ||
// Build a build variables instance. | ||
Build() BuildVariables | ||
} | ||
|
||
// NewBuildVariablesBuilder creates a new BuildVariablesBuilder. | ||
func NewBuildVariablesBuilder() BuildVariablesBuilder { | ||
return &defaultBuilder{ | ||
bv: make(BuildVariables), | ||
} | ||
} | ||
|
||
type defaultBuilder struct { | ||
bv BuildVariables | ||
} | ||
|
||
func (d defaultBuilder) Add(key string, resolver Resolver) BuildVariablesBuilder { | ||
d.bv[key] = resolver | ||
return d | ||
} | ||
|
||
func (d defaultBuilder) ConditionallyAdd(cnd func() bool, key string, resolver Resolver) BuildVariablesBuilder { | ||
if cnd() { | ||
return d.Add(key, resolver) | ||
} | ||
return d | ||
} | ||
|
||
func (d defaultBuilder) Build() BuildVariables { | ||
return d.bv | ||
} |
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
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
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
package metadata | ||
|
||
// Image holds information about companion image reference. | ||
//goland:noinspection GoUnusedGlobalVariable | ||
var Image = "" | ||
import "fmt" | ||
|
||
var ( | ||
// Image holds information about companion image reference. | ||
Image = "" //nolint:gochecknoglobals | ||
// ImageBasename holds a basename of a image, so the development reference | ||
// could be built from it. | ||
ImageBasename = "" //nolint:gochecknoglobals | ||
) | ||
|
||
// ResolveImage will try to resolve the image reference from set values. If | ||
// Image is given it will be used, otherwise the ImageBasename and Version will | ||
// be used. | ||
func ResolveImage() string { | ||
if Image == "" { | ||
return fmt.Sprintf("%s:%s", ImageBasename, Version) | ||
} | ||
return Image | ||
} | ||
|
||
// ImagePath return a path to the image variable. | ||
func ImagePath() string { | ||
return "github.com/wavesoftware/go-magetasks/tests/example/pkg/metadata.Image" | ||
return importPath("Image") | ||
} | ||
|
||
// ImageBasenamePath return a path to the image basename variable. | ||
func ImageBasenamePath() string { | ||
return importPath("ImageBasename") | ||
} |
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,18 @@ | ||
package metadata | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
) | ||
|
||
type marker struct{} | ||
|
||
func importPath(variable string) string { | ||
m := marker{} | ||
p := findPackageForType(m) | ||
return fmt.Sprintf("%s.%s", p, variable) | ||
} | ||
|
||
func findPackageForType(any interface{}) string { | ||
return reflect.TypeOf(any).PkgPath() | ||
} |
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