-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_options_test.go
More file actions
74 lines (66 loc) · 2.31 KB
/
Copy pathexample_options_test.go
File metadata and controls
74 lines (66 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package lsremote_test
import (
"context"
"fmt"
"log"
"os"
"time"
lsremote "github.com/hiddeco/go-ls-remote"
"github.com/hiddeco/go-ls-remote/trace"
"github.com/hiddeco/go-ls-remote/transport"
filet "github.com/hiddeco/go-ls-remote/transport/file"
gitt "github.com/hiddeco/go-ls-remote/transport/git"
httpt "github.com/hiddeco/go-ls-remote/transport/http"
)
// ExampleWithTransports composes a registry covering schemes beyond
// the HTTPS-only default. SSH and `git://` are intentionally opt-in so
// a misconfigured caller cannot accidentally reach a non-HTTPS remote;
// the same pattern adds them once the per-transport options
// (credentials, host-key callback) have been wired in. See the `ssht`
// and `gitt` package examples for the per-transport setup.
func ExampleWithTransports() {
reg := transport.NewRegistry(
httpt.New(),
gitt.New(),
filet.New(),
)
ctx := context.Background()
refs, err := lsremote.ListRefs(ctx, "git://example.com/repo.git",
lsremote.RefsRequest{},
lsremote.WithTransports(reg))
if err != nil {
log.Fatal(err)
}
fmt.Println(len(refs), "refs")
}
// ExampleWithProtocol pins protocol-version negotiation. Auto-
// negotiation (the default) prefers v2 and falls back to v0; pin v0
// only when the caller knows the remote does not understand v2, or to
// reproduce a historical interaction.
func ExampleWithProtocol() {
refs, err := lsremote.ListRefs(context.Background(),
"https://example.com/git/legacy.git",
lsremote.RefsRequest{},
lsremote.WithProtocol(lsremote.ProtocolV0))
if err != nil {
log.Fatal(err)
}
fmt.Println(len(refs), "refs")
}
// ExampleWithTracer captures pkt-line, HTTP, and command lifecycle
// events through a [trace.Tracer]. [trace.NewWriterTracer] dumps a
// human-readable summary to an [io.Writer], comparable to canonical
// Git's `GIT_TRACE_PACKET=` output; implement [trace.Tracer] directly
// for structured or machine-readable consumption.
func ExampleWithTracer() {
tracer := trace.NewWriterTracer(os.Stderr)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := lsremote.ListRefs(ctx,
"https://github.com/octocat/Hello-World.git",
lsremote.RefsRequest{},
lsremote.WithTracer(tracer))
if err != nil {
log.Fatal(err) //nolint:gocritic // example doc pattern: log.Fatal mirrors typical caller code
}
}