MCPcopy Create free account
hub / github.com/mpolden/echoip / Parse

Function Parse

useragent/useragent.go:14–40  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

12}
13
14func Parse(s string) UserAgent {
15 parts := strings.SplitN(s, "/", 2)
16 var version, comment string
17 if len(parts) > 1 {
18 // If first character is a number, treat it as version
19 if len(parts[1]) > 0 && parts[1][0] >= 48 && parts[1][0] <= 57 {
20 rest := strings.SplitN(parts[1], " ", 2)
21 version = rest[0]
22 if len(rest) > 1 {
23 comment = rest[1]
24 }
25 } else {
26 comment = parts[1]
27 }
28 } else {
29 parts = strings.SplitN(s, " ", 2)
30 if len(parts) > 1 {
31 comment = parts[1]
32 }
33 }
34 return UserAgent{
35 Product: parts[0],
36 Version: version,
37 Comment: comment,
38 RawValue: s,
39 }
40}

Callers 3

userAgentFromRequestFunction · 0.92
cliMatcherFunction · 0.92
TestParseFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseFunction · 0.68