package main import ( "fmt" "io" "log" "net/url" "os" "strings" sr "tildegit.org/tjp/sliderule" "tildegit.org/tjp/sliderule/gemini" ) func main() { if len(os.Args) < 2 { fmt.Fprintf(os.Stderr, "usage: %s \n", os.Args[0]) } certfile, keyfile := envConfig() // build a client var client gemini.Client if certfile != "" && keyfile != "" { tlsConf, err := gemini.FileTLS(certfile, keyfile) if err != nil { log.Fatal(err) } client = gemini.NewClient(tlsConf) } // parse the URL and build the request request := &sr.Request{URL: buildURL(os.Args[1])} // fetch the response response, err := client.RoundTrip(request) if err != nil { log.Fatal(err) } defer response.Close() if response.Status != gemini.StatusSuccess { log.Fatalf("%d %s\n", response.Status, response.Meta) } if _, err := io.Copy(os.Stdout, response.Body); err != nil { log.Fatal(err) } } func envConfig() (string, string) { return os.Getenv("CLIENT_CERTIFICATE"), os.Getenv("CLIENT_PRIVATEKEY") } func buildURL(raw string) *url.URL { if strings.HasPrefix(raw, "//") { raw = "gemini:" + raw } u, err := url.Parse(raw) if err != nil { log.Fatal(err) } return u }