func toHTTPRequest(p *logtypepb.HttpRequest) (*logging.HTTPRequest, error) { if p == nil { return nil, nil } u, err := url.Parse(p.RequestUrl) if err != nil { return nil, err } var dur time.Duration if p.Latency != nil { dur, err = ptypes.Duration(p.Latency) if err != nil { return nil, err } } hr := &http.Request{ Method: p.RequestMethod, URL: u, Header: map[string][]string{}, } if p.UserAgent != "" { hr.Header.Set("User-Agent", p.UserAgent) } if p.Referer != "" { hr.Header.Set("Referer", p.Referer) } return &logging.HTTPRequest{ Request: hr, RequestSize: p.RequestSize, Status: int(p.Status), ResponseSize: p.ResponseSize, Latency: dur, RemoteIP: p.RemoteIp, CacheHit: p.CacheHit, CacheValidatedWithOriginServer: p.CacheValidatedWithOriginServer, }, nil }
func ExampleOperation_Metadata() { op, err := bestMomentInHistory() if err != nil { // TODO: Handle err. } // The operation might contain metadata. // In this example, the metadata contains the estimated length of time // the operation might take to complete. var meta duration.Duration if err := op.Metadata(&meta); err != nil { // TODO: Handle err. } d, err := ptypes.Duration(&meta) if err == ErrNoMetadata { fmt.Println("no metadata") } else if err != nil { // TODO: Handle err. } else { fmt.Println(d) } // Output: // 1h0m0s }