Skip to content

Instantly share code, notes, and snippets.

@richardlehane
Created September 16, 2014 10:51
Show Gist options
  • Save richardlehane/1d55ef5f9c93ded37df9 to your computer and use it in GitHub Desktop.
Save richardlehane/1d55ef5f9c93ded37df9 to your computer and use it in GitHub Desktop.
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