48 lines
681 B
Go
48 lines
681 B
Go
package squid
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type Request struct {
|
|
Id int
|
|
Url string
|
|
Args map[string]string
|
|
}
|
|
|
|
func ParseRequest(line string) *Request {
|
|
fields := strings.Fields(line)
|
|
|
|
if len(fields) < 1 {
|
|
return nil
|
|
}
|
|
|
|
r := Request{}
|
|
r.Id = -1
|
|
r.Args = make(map[string]string)
|
|
|
|
for i, field := range fields {
|
|
if i == 0 {
|
|
if val, err := strconv.Atoi(field); err == nil {
|
|
r.Id = val
|
|
continue
|
|
}
|
|
}
|
|
if r.Url == "" {
|
|
r.Url = field
|
|
continue
|
|
}
|
|
if strings.Contains(field, "=") {
|
|
kv := strings.SplitN(field, "=", 2)
|
|
r.Args[kv[0]] = kv[1]
|
|
}
|
|
}
|
|
|
|
return &r
|
|
}
|
|
|
|
func (r *Request) MakeResponse() *Response {
|
|
return &Response{Id: r.Id}
|
|
}
|