-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpush_multiple.go
73 lines (56 loc) · 1.67 KB
/
push_multiple.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"log"
"os"
"github.com/FourtekIT/devnagri-cli/config"
"gopkg.in/resty.v1"
)
func main() {
var ClientID = config.FetchAndValidate("ClientID") // returns string
var ClientSecret = config.FetchAndValidate("ClientSecret") // returns string
var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string
var AccessToken = config.FetchAndValidate("AccessToken") // returns string
//var RootFolder = config.FetchAndValidate("RootFolder") // returns string
var SourceLanguage = config.FetchAndValidate("SourceLanguage")
//TODO: send all the files within a SourceLanguage target folder
filename := "./" + SourceLanguage + "/strings.xml"
var Extension = config.FetchAndValidate("Extension")
resp, err := resty.R().
SetHeader("Accept", "application/json").
SetHeader("Content-Type", "multipart/form-data").
SetAuthToken(AccessToken).
SetFile("file[0][file]", filename).
SetFormData(map[string]string{
"client_id": ClientID,
"client_secret": ClientSecret,
"project_key": ProjectKey,
"file[0][hash]": sha256Hash(filename),
"file[0][extension]": Extension,
"file[0][file_type]": "xml",
"file[0][location]": filename,
}).
Post("http://dev.devnagri.co.in/api/project/push")
if err != nil {
panic(err)
}
fmt.Println(resp)
}
func sha256Hash(fileName string) string {
f, err := os.Open(fileName)
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
//fmt.Printf("%x", h.Sum(nil))
//return h.Sum(nil)
hashString := hex.EncodeToString(h.Sum(nil))
return hashString
}