Created
September 16, 2014 10:51
-
-
Save richardlehane/1d55ef5f9c93ded37df9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package itforarchivists | |
import ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
"github.com/richardlehane/siegfried/pkg/core" | |
"github.com/richardlehane/siegfried/pkg/pronom" | |
) | |
type Identification struct { | |
Puids []string | |
} | |
func (i *Identification) Json() string { | |
byt, _ := json.Marshal(i) | |
return string(byt) | |
} | |
func identify(r *http.Request) (*Identification, error) { | |
s := core.NewSiegfried() | |
p, err := pronom.Load("public/latest/pronom.gob") | |
if err != nil { | |
return nil, err | |
} | |
s.AddIdentifier(p) | |
id := &Identification{make([]string, 0)} | |
f, _, err := r.FormFile("file") | |
if err != nil { | |
return nil, err | |
} | |
defer f.Close() | |
c, err := s.Identify(f, "") | |
if err != nil { | |
return nil, fmt.Errorf("failed to identify %v, got: %v", p, err) | |
} | |
for i := range c { | |
id.Puids = append(id.Puids, i.String()) | |
} | |
return id, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment