mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-26 11:36:26 -08:00
cmd/tailscale/tslockjsonv1: add examples to the docs
This patch adds examples of unmarshalling tslockjsonv1.LogResponse and tslockjsonv1.StatusResponse to the documentation. Updates #17613 Signed-off-by: Simon Law <[email protected]>
This commit is contained in:
1 parent
3093e4523c
commit
7cf85bdaad
2 files changed
+64
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package tslockjsonv1_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"tailscale.com/cmd/tailscale/tslockjsonv1"
|
||||
)
|
||||
|
||||
func ExampleLogResponse() {
|
||||
cmd := exec.Command("tailscale", "lock", "log", "--json")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
if err, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
fmt.Fprintf(os.Stderr, "%s", err.Stderr)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var logs tslockjsonv1.LogResponse
|
||||
if err := json.Unmarshal(out, &logs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, msg := range logs.Messages {
|
||||
fmt.Printf("{kind: %s, key id: %s, key: %+v}\n", msg.AUM.MessageKind, msg.AUM.KeyID, msg.AUM.Key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package tslockjsonv1_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"tailscale.com/cmd/tailscale/tslockjsonv1"
|
||||
)
|
||||
|
||||
func ExampleStatusResponse() {
|
||||
cmd := exec.Command("tailscale", "lock", "status", "--json")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
if err, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||
fmt.Fprintf(os.Stderr, "%s", err.Stderr)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var status tslockjsonv1.StatusResponse
|
||||
if err := json.Unmarshal(out, &status); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("{enabled: %t, public key: %s, node key: %s}\n", status.Enabled, status.PublicKey, status.NodeKey)
|
||||
}
|
||||
Reference in new issue
Block a user