-
Notifications
You must be signed in to change notification settings - Fork 0
/
tify.go
42 lines (36 loc) · 796 Bytes
/
tify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/json"
"fmt"
"net/url"
)
type State struct {
Manifest string `json:"manifest"`
Options json.RawMessage `json:"options"`
}
type States []State
func (s States) Json() []byte {
a, _ := json.Marshal(s)
return a
}
func Tify(state string) (States, error) {
u, err := url.Parse(state)
if err != nil {
return nil, err
}
params := u.Query()
var states States
for i := 0; i < len(params)/2; i++ {
manifestKey := "manifest"
tifyKey := "tify"
if i > 0 {
manifestKey = fmt.Sprintf("manifest%d", i)
tifyKey = fmt.Sprintf("tify%d", i)
}
manifest := params.Get(manifestKey)
options := params.Get(tifyKey)
iiifInfo := State{Manifest: manifest, Options: []byte(options)}
states = append(states, iiifInfo)
}
return states, nil
}