-
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.
inject opts instead of context.withValue
- Loading branch information
1 parent
0b33606
commit 4847311
Showing
4 changed files
with
121 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net" | ||
) | ||
|
||
type optionKey string | ||
type options struct { | ||
inputAddress string // BUG(low) remove | ||
address net.IP | ||
port uint | ||
callsign string | ||
comment string | ||
ssid string | ||
longitude float64 | ||
latitude float64 | ||
showVersion bool | ||
} | ||
|
||
func ctxWithOptions(ctx context.Context, opts options) context.Context { | ||
key := optionKey("options") | ||
return context.WithValue(context.Background(), key, opts) | ||
} | ||
|
||
func ctxOptions(ctx context.Context) (options, error) { | ||
opts, ok := ctx.Value(optionKey("options")).(options) | ||
if !ok { | ||
return opts, errors.New("unable to return options") | ||
} | ||
|
||
return opts, nil | ||
argAddress string | ||
callsign string | ||
comment string | ||
ssid string | ||
address net.IP | ||
longitude float64 | ||
latitude float64 | ||
port uint | ||
showVersion bool | ||
} |
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