-
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.
api: Move fleetlock api types to new package
Signed-off-by: Heathcliff <[email protected]>
- Loading branch information
1 parent
d432951
commit 1fc1ee4
Showing
8 changed files
with
86 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
) | ||
|
||
// Parse an http request body and extract the parameters | ||
func ParseRequest(body io.ReadCloser) (FleetLockRequest, error) { | ||
var res FleetLockRequest | ||
err := json.NewDecoder(body).Decode(&res) | ||
if err != nil { | ||
return FleetLockRequest{}, err | ||
} | ||
return res, nil | ||
} | ||
|
||
// Parse an http response body and extract the parameters | ||
func ParseResponse(body io.ReadCloser) (FleetLockResponse, error) { | ||
var res FleetLockResponse | ||
err := json.NewDecoder(body).Decode(&res) | ||
if err != nil { | ||
return FleetLockResponse{}, err | ||
} | ||
return res, nil | ||
} | ||
|
||
// Create a new http request pody based on the provided parameters | ||
func PrepareRequest(group, id string) (io.Reader, error) { | ||
req := FleetLockRequest{ | ||
Client: FleetLockRequestClient{ | ||
ID: id, | ||
Group: group, | ||
}, | ||
} | ||
body, err := json.Marshal(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return bytes.NewReader(body), 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
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