-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
63 lines (52 loc) · 1.02 KB
/
cli.go
File metadata and controls
63 lines (52 loc) · 1.02 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
package main
import (
"fmt"
"io"
"log/slog"
"net/url"
)
type logLevelValue struct {
slog.Level
}
func (l *logLevelValue) Set(s string) error {
return l.UnmarshalText([]byte(s))
}
func (l *logLevelValue) String() string {
return l.Level.String()
}
type logFormatValue struct {
format string
}
func (l *logFormatValue) Set(s string) error {
if s != "text" && s != "json" {
return fmt.Errorf("invalid log format: %s", s)
}
l.format = s
return nil
}
func (l *logFormatValue) String() string {
return l.format
}
func (l *logFormatValue) Handler(f io.Writer, opts *slog.HandlerOptions) slog.Handler {
switch l.format {
case "text":
return slog.NewTextHandler(f, opts)
case "json":
return slog.NewJSONHandler(f, opts)
}
panic(fmt.Sprintf("invalid log format: %s", l.format))
}
type beaconUrlValue struct {
url.URL
}
func (b *beaconUrlValue) Set(s string) error {
u, err := url.Parse(s)
if err != nil {
return err
}
b.URL = *u
return nil
}
func (b *beaconUrlValue) String() string {
return b.URL.String()
}