-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(agent,hass,tracker): rework api request/response logic
- move parameters needed for rest api into context values - simplify responses; either return an error or a specific type - tracker logic streamlined for better response handling
- Loading branch information
Showing
21 changed files
with
1,004 additions
and
1,133 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
21 changes: 20 additions & 1 deletion
21
internal/hass/api/requestType.go → internal/hass/api/apiTypes.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
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,33 @@ | ||
// Copyright (c) 2023 Joshua Rich <[email protected]> | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
package api | ||
|
||
import "context" | ||
|
||
type APIConfig struct { | ||
APIURL string | ||
Secret string | ||
} | ||
|
||
// key is an unexported type for keys defined in this package. | ||
// This prevents collisions with keys defined in other packages. | ||
type key int | ||
|
||
// userKey is the key for user.User values in Contexts. It is | ||
// unexported; clients use user.NewContext and user.FromContext | ||
// instead of using this key directly. | ||
var userKey key | ||
|
||
// NewContext returns a new Context that carries value u. | ||
func NewContext(ctx context.Context, c *APIConfig) context.Context { | ||
return context.WithValue(ctx, userKey, c) | ||
} | ||
|
||
// FromContext returns the User value stored in ctx, if any. | ||
func FromContext(ctx context.Context) (*APIConfig, bool) { | ||
u, ok := ctx.Value(userKey).(*APIConfig) | ||
return u, ok | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.