-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleGoScript.go
56 lines (45 loc) · 1.12 KB
/
exampleGoScript.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
package main
import (
"bufio"
"encoding/base64"
"fmt"
"github.com/kittycad/kittycad.go"
"io/ioutil"
"os"
"strings"
)
func main() {
// Create a new client with your token parsed from the environment variable:
// KITTYCAD_API_TOKEN.
client, err := kittycad.NewClientFromEnv("your apps user agent")
if err != nil {
panic(err)
}
input, _ := os.Open("./ORIGINALVOXEL-3.obj")
content, _ := ioutil.ReadAll(bufio.NewReader(input))
// Encode as base64.
myReader := strings.NewReader(base64.StdEncoding.EncodeToString(content))
fc, err := client.File.CreateConversion("stl", "obj", myReader)
if err != nil {
panic(err)
}
fmt.Println("File conversion id: ", fc.ID)
fmt.Println("File conversion status: ", fc.Status)
decoded, err := base64.StdEncoding.DecodeString(fc.Output)
if err != nil {
panic(err)
}
output_file_path := "./output.stl"
fmt.Println("Saving output to ", output_file_path)
output, err := os.Create(output_file_path)
if err != nil {
panic(err)
}
defer output.Close()
if _, err := output.Write(decoded); err != nil {
panic(err)
}
if err := output.Sync(); err != nil {
panic(err)
}
}