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

Side by Side Diff: go/src/infra/libs/gitiles/priv_objRequest.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: more tests and refactors Created 6 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package gitiles
6
7 import (
8 "fmt"
9 "infra/libs/git"
10 "net/http"
11 )
12
13 // Types ///////////////////////////////////////////////////////////////////////
14
15 type objRequest struct {
16 textRequest
17 resultChan chan<- objectResult
18 }
19
20 type objectResult struct {
21 err error
22 object git.InternableObject
23 }
24
25 // Vars ////////////////////////////////////////////////////////////////////////
26
27 var dataLoader = map[string]func([]byte) (git.InternableObject, error){
28 "blob": func(d []byte) (git.InternableObject, error) { return git.NewB lobFromRaw(d), nil },
29 "tree": func(d []byte) (git.InternableObject, error) { return git.NewT reeFromText(d) },
30 "commit": func(d []byte) (git.InternableObject, error) { return git.NewC ommitFromRaw(d) },
31 }
32
33 // Member functions ////////////////////////////////////////////////////////////
34
35 func (o objRequest) Process(rsp *http.Response, err error) {
36 var rslt objectResult
37
38 data, err := o.internalProcess(rsp, err)
39 if err != nil {
40 rslt.err = err
41 } else {
42 typ := rsp.Header.Get("X-Gitiles-Object-Type")
43 loader, ok := dataLoader[typ]
44 if !ok {
45 rslt.err = fmt.Errorf("Unknown object type %#v", typ)
46 } else {
47 rslt.object, rslt.err = loader(data)
48 }
49 }
50
51 o.resultChan <- rslt
52 }
OLDNEW
« no previous file with comments | « go/src/infra/libs/gitiles/priv_jsonRequest.go ('k') | go/src/infra/libs/gitiles/priv_textRequest.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698