mirror of
https://github.com/sajari/docconv.git
synced 2026-10-17 05:30:56 +08:00
93312f47fc
- Some methods have been changed to return an error as their last argument - Log calls inside various functions have been removed - Use a v1 tag if you need the previous signature
44 lines
777 B
Go
44 lines
777 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"code.sajari.com/docconv/v2/client"
|
|
)
|
|
|
|
var (
|
|
path = flag.String("path", "", "`path` to file to convert")
|
|
endpoint = flag.String("endpoint", "", "docconv HTTP server to use for conversion")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *path == "" {
|
|
fmt.Println("must set -path")
|
|
os.Exit(1)
|
|
}
|
|
|
|
var opts []client.Opt
|
|
if *endpoint != "" {
|
|
opts = append(opts, client.WithEndpoint(*endpoint))
|
|
}
|
|
|
|
c := client.New(opts...)
|
|
resp, err := client.ConvertPath(c, *path)
|
|
if err != nil {
|
|
fmt.Printf("Could not convert: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(resp); err != nil {
|
|
fmt.Printf("Could not encode response: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|