MCPcopy
hub / github.com/uber-go/zap / newSink

Method newSink

sink.go:93–117  ·  view source on GitHub ↗
(rawURL string)

Source from the content-addressed store, hash-verified

91}
92
93func (sr *sinkRegistry) newSink(rawURL string) (Sink, error) {
94 // URL parsing doesn't work well for Windows paths such as `c:\log.txt`, as scheme is set to
95 // the drive, and path is unset unless `c:/log.txt` is used.
96 // To avoid Windows-specific URL handling, we instead check IsAbs to open as a file.
97 // filepath.IsAbs is OS-specific, so IsAbs('c:/log.txt') is false outside of Windows.
98 if filepath.IsAbs(rawURL) {
99 return sr.newFileSinkFromPath(rawURL)
100 }
101
102 u, err := url.Parse(rawURL)
103 if err != nil {
104 return nil, fmt.Errorf("can't parse %q as a URL: %v", rawURL, err)
105 }
106 if u.Scheme == "" {
107 u.Scheme = schemeFile
108 }
109
110 sr.mu.Lock()
111 factory, ok := sr.factories[u.Scheme]
112 sr.mu.Unlock()
113 if !ok {
114 return nil, &errSinkNotFound{u.Scheme}
115 }
116 return factory(u)
117}
118
119// RegisterSink registers a user-supplied factory for all sinks with a
120// particular scheme.

Callers 2

TestWindowsPathsFunction · 0.80
openFunction · 0.80

Calls 2

newFileSinkFromPathMethod · 0.95
ErrorfMethod · 0.65

Tested by 1

TestWindowsPathsFunction · 0.64