-
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.
* allow scheme-less URIs, block out app/ package * Update to allow scheme-less strings; move guts of cmd/runtimevar in to /app --------- Co-authored-by: sfomuseumbot <sfomuseumbot@localhost>
- Loading branch information
1 parent
1f05295
commit 14c02d4
Showing
11 changed files
with
240 additions
and
35 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,15 @@ | ||
package runtimevar | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/sfomuseum/go-flags/flagset" | ||
) | ||
|
||
var timeout int | ||
|
||
func DefaultFlagSet() *flag.FlagSet { | ||
fs := flagset.NewFlagSet("publish") | ||
fs.IntVar(&timeout, "timeout", 0, "The maximum number of second in which a variable can be resolved. If 0 no timeout is applied.") | ||
return fs | ||
} |
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,34 @@ | ||
package runtimevar | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/sfomuseum/go-flags/flagset" | ||
) | ||
|
||
type RunOptions struct { | ||
Timeout int | ||
Vars []string | ||
} | ||
|
||
func OptionsFromFlagSet(ctx context.Context, fs *flag.FlagSet) (*RunOptions, error) { | ||
|
||
flagset.Parse(fs) | ||
|
||
err := flagset.SetFlagsFromEnvVars(fs, "RUNTIMEVAR") | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to derive flags from environment variables, %w", err) | ||
} | ||
|
||
vars := fs.Args() | ||
|
||
opts := &RunOptions{ | ||
Timeout: timeout, | ||
Vars: vars, | ||
} | ||
|
||
return opts, nil | ||
} |
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,51 @@ | ||
package runtimevar | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/sfomuseum/runtimevar" | ||
) | ||
|
||
func Run(ctx context.Context, logger *slog.Logger) error { | ||
fs := DefaultFlagSet() | ||
return RunWithFlagSet(ctx, fs, logger) | ||
} | ||
|
||
func RunWithFlagSet(ctx context.Context, fs *flag.FlagSet, logger *slog.Logger) error { | ||
|
||
opts, err := OptionsFromFlagSet(ctx, fs) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to derive options from flagset, %w", err) | ||
} | ||
|
||
return RunWithOptions(ctx, opts, logger) | ||
} | ||
|
||
func RunWithOptions(ctx context.Context, opts *RunOptions, logger *slog.Logger) error { | ||
|
||
if opts.Timeout > 0 { | ||
|
||
c, cancel := context.WithTimeout(ctx, time.Duration(opts.Timeout)*time.Second) | ||
defer cancel() | ||
|
||
ctx = c | ||
} | ||
|
||
for _, uri := range opts.Vars { | ||
|
||
str_var, err := runtimevar.StringVar(ctx, uri) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to derive variable, %w", err) | ||
} | ||
|
||
fmt.Printf(str_var) | ||
} | ||
|
||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
vendor/github.com/sfomuseum/go-flags/flagset/flagset.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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