mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
add entry point, context and util
This commit is contained in:
parent
33139b103f
commit
04172d5b9d
20
cmd/context.go
Normal file
20
cmd/context.go
Normal file
@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
||||
)
|
||||
|
||||
type clientKey string
|
||||
|
||||
func WithContext(ctx context.Context, client *xair.XAirClient) context.Context {
|
||||
return context.WithValue(ctx, clientKey("oscClient"), client)
|
||||
}
|
||||
|
||||
func ClientFromContext(ctx context.Context) *xair.XAirClient {
|
||||
if client, ok := ctx.Value(clientKey("oscClient")).(*xair.XAirClient); ok {
|
||||
return client
|
||||
}
|
||||
return nil
|
||||
}
|
||||
13
cmd/util.go
Normal file
13
cmd/util.go
Normal file
@ -0,0 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func mustConv(levelStr string) float64 {
|
||||
level, err := strconv.ParseFloat(levelStr, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return level
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user