Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: logdog/common/types/streamaddr.go

Issue 2895233004: [logdog/common/types] make StreamAddr implement flag.Value. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | logdog/common/types/streamaddr_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package types 5 package types
6 6
7 import ( 7 import (
8 "flag"
8 "net/url" 9 "net/url"
9 "strings" 10 "strings"
10 11
11 "github.com/luci/luci-go/common/errors" 12 "github.com/luci/luci-go/common/errors"
12 "github.com/luci/luci-go/luci_config/common/cfgtypes" 13 "github.com/luci/luci-go/luci_config/common/cfgtypes"
13 ) 14 )
14 15
15 const logDogURLScheme = "logdog" 16 const logDogURLScheme = "logdog"
16 17
17 // StreamAddr is a fully-qualified LogDog stream address. 18 // StreamAddr is a fully-qualified LogDog stream address.
18 type StreamAddr struct { 19 type StreamAddr struct {
19 // Host is the LogDog host. 20 // Host is the LogDog host.
20 Host string 21 Host string
21 22
22 // Project is the LUCI project name that this log belongs to. 23 // Project is the LUCI project name that this log belongs to.
23 Project cfgtypes.ProjectName 24 Project cfgtypes.ProjectName
24 25
25 // Path is the LogDog stream path. 26 // Path is the LogDog stream path.
26 Path StreamPath 27 Path StreamPath
27 } 28 }
28 29
30 var _ flag.Value = (*StreamAddr)(nil)
31
32 // Set implements flag.Value
33 func (s *StreamAddr) Set(v string) error {
34 a, err := ParseURL(v)
35 if err != nil {
36 return err
37 }
38 *s = *a
39 return nil
40 }
41
29 // String returns a string representation of this address. 42 // String returns a string representation of this address.
30 func (s *StreamAddr) String() string { return s.URL().String() } 43 func (s *StreamAddr) String() string { return s.URL().String() }
31 44
32 // URL returns a LogDog URL that represents this Stream. 45 // URL returns a LogDog URL that represents this Stream.
33 func (s *StreamAddr) URL() *url.URL { 46 func (s *StreamAddr) URL() *url.URL {
34 return &url.URL{ 47 return &url.URL{
35 Scheme: logDogURLScheme, 48 Scheme: logDogURLScheme,
36 Host: s.Host, 49 Host: s.Host,
37 Path: strings.Join([]string{"", string(s.Project), string(s.Pa th)}, "/"), 50 Path: strings.Join([]string{"", string(s.Project), string(s.Pa th)}, "/"),
38 } 51 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 87 }
75 88
76 if err := addr.Path.Validate(); err != nil { 89 if err := addr.Path.Validate(); err != nil {
77 return nil, errors.Annotate(err).Reason("invalid stream path: %( path)q"). 90 return nil, errors.Annotate(err).Reason("invalid stream path: %( path)q").
78 D("path", addr.Path). 91 D("path", addr.Path).
79 Err() 92 Err()
80 } 93 }
81 94
82 return &addr, nil 95 return &addr, nil
83 } 96 }
OLDNEW
« no previous file with comments | « no previous file | logdog/common/types/streamaddr_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698