-
Notifications
You must be signed in to change notification settings - Fork 4
/
oas_servers_gen.go
62 lines (54 loc) · 1.43 KB
/
oas_servers_gen.go
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
// Code generated by ogen, DO NOT EDIT.
package sentryapi
import (
"fmt"
"net/url"
"github.com/go-faster/errors"
)
// SentryURLServer is a server URL template.
type SentryURLServer struct {
ProjectID string `json:"projectID" yaml:"projectID"`
}
// MustPath returns the computed path. It panics if any error occurs.
func (s SentryURLServer) MustPath() string {
return errors.Must(s.Path())
}
// Path returns the computed path.
func (s SentryURLServer) Path() (string, error) {
raw, err := s.Build()
if err != nil {
return "", err
}
u, err := url.Parse(raw)
if err != nil {
return "", err
}
return u.Path, nil
}
// MustBuild returns the computed server URL. It panics if any error occurs.
func (s SentryURLServer) MustBuild() string {
return errors.Must(s.Build())
}
// Build returns the computed server URL.
//
// If variable is empty, it uses the default value.
// If spec defines an enum and given value is not in the enum, it returns an error.
//
// Notice that given values will not be escaped and may cause invalid URL.
func (s SentryURLServer) Build() (string, error) {
zeroOr := func(s string, def string) string {
if s == "" {
return def
}
return s
}
s.ProjectID = zeroOr(s.ProjectID, "unknown")
// Validate "projectID"
switch s.ProjectID {
default:
return "", errors.Errorf("param %q: unexpected value %q", "projectID", s.ProjectID)
}
return fmt.Sprintf("http://localhost:8000/api/%s",
s.ProjectID,
), nil
}