-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So they use Clue for observability instead of the deprecated Goa middlewares.
- Loading branch information
Showing
67 changed files
with
3,282 additions
and
3,197 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
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,11 +1,11 @@ | ||
|
||
|
||
{{ comment "Wait for signal." }} | ||
logger.Printf("exiting (%v)", <-errc) | ||
log.Printf(ctx, "exiting (%v)", <-errc) | ||
|
||
{{ comment "Send cancellation signal to the goroutines." }} | ||
cancel() | ||
|
||
wg.Wait() | ||
logger.Println("exited") | ||
log.Printf(ctx, "exited") | ||
} |
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,9 +1,13 @@ | ||
|
||
|
||
{{ comment "Setup logger. Replace logger with your own log package of choice." }} | ||
var ( | ||
logger *log.Logger | ||
) | ||
{ | ||
logger = log.New(os.Stderr, "[{{ .APIPkg }}] ", log.Ltime) | ||
} | ||
format := log.FormatJSON | ||
if log.IsTerminal() { | ||
format = log.FormatTerminal | ||
} | ||
ctx := log.Context(context.Background(), log.WithFormat(format)) | ||
if *dbgF { | ||
ctx = log.Context(ctx, log.WithDebug()) | ||
log.Debugf(ctx, "debug logs enabled") | ||
} | ||
log.Print(ctx, log.KV{K: "http-port", V: *httpPortF}) |
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,108 @@ | ||
func main() { | ||
var ( | ||
hostF = flag.String("host", "localhost", "Server host (valid values: localhost)") | ||
addrF = flag.String("url", "", "URL to service host") | ||
|
||
verboseF = flag.Bool("verbose", false, "Print request and response details") | ||
vF = flag.Bool("v", false, "Print request and response details") | ||
timeoutF = flag.Int("timeout", 30, "Maximum number of seconds to wait for response") | ||
) | ||
flag.Usage = usage | ||
flag.Parse() | ||
var ( | ||
addr string | ||
timeout int | ||
debug bool | ||
) | ||
{ | ||
addr = *addrF | ||
if addr == "" { | ||
switch *hostF { | ||
case "localhost": | ||
addr = "http://localhost:80" | ||
default: | ||
fmt.Fprintf(os.Stderr, "invalid host argument: %q (valid hosts: localhost)\n", *hostF) | ||
os.Exit(1) | ||
} | ||
} | ||
timeout = *timeoutF | ||
debug = *verboseF || *vF | ||
} | ||
|
||
var ( | ||
scheme string | ||
host string | ||
) | ||
{ | ||
u, err := url.Parse(addr) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "invalid URL %#v: %s\n", addr, err) | ||
os.Exit(1) | ||
} | ||
scheme = u.Scheme | ||
host = u.Host | ||
} | ||
var ( | ||
endpoint goa.Endpoint | ||
payload any | ||
err error | ||
) | ||
{ | ||
switch scheme { | ||
case "http", "https": | ||
endpoint, payload, err = doHTTP(scheme, host, timeout, debug) | ||
case "grpc", "grpcs": | ||
endpoint, payload, err = doGRPC(scheme, host, timeout, debug) | ||
default: | ||
fmt.Fprintf(os.Stderr, "invalid scheme: %q (valid schemes: grpc|http)\n", scheme) | ||
os.Exit(1) | ||
} | ||
} | ||
if err != nil { | ||
if err == flag.ErrHelp { | ||
os.Exit(0) | ||
} | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
fmt.Fprintln(os.Stderr, "run '"+os.Args[0]+" --help' for detailed usage.") | ||
os.Exit(1) | ||
} | ||
|
||
data, err := endpoint(context.Background(), payload) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
if data != nil { | ||
m, _ := json.MarshalIndent(data, "", " ") | ||
fmt.Println(string(m)) | ||
} | ||
} | ||
|
||
func usage() { | ||
fmt.Fprintf(os.Stderr, `%s is a command line client for the test api API. | ||
|
||
Usage: | ||
%s [-host HOST][-url URL][-timeout SECONDS][-verbose|-v] SERVICE ENDPOINT [flags] | ||
|
||
-host HOST: server host (localhost). valid values: localhost | ||
-url URL: specify service URL overriding host URL (http://localhost:8080) | ||
-timeout: maximum number of seconds to wait for response (30) | ||
-verbose|-v: print request and response details (false) | ||
|
||
Commands: | ||
%s | ||
Additional help: | ||
%s SERVICE [ENDPOINT] --help | ||
|
||
Example: | ||
%s | ||
`, os.Args[0], os.Args[0], indent(httpUsageCommands()), os.Args[0], indent(httpUsageExamples())) | ||
} | ||
|
||
func indent(s string) string { | ||
if s == "" { | ||
return "" | ||
} | ||
return " " + strings.Replace(s, "\n", "\n ", -1) | ||
} |
Oops, something went wrong.