Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "fui", Short: "BtrFaaS HTTP UI", Long: `BtrFaaS HTTP UI`, Run: func(cmd *cobra.Command, args []string) { gateway, _ := cmd.Flags().GetString("gateway") certPool := x509.NewCertPool() ca, err := ioutil.ReadFile("/run/secrets/btrfaas-ca-cert.pem") if err != nil { log.Fatal(err) } if ok := certPool.AppendCertsFromPEM(ca); !ok { log.Fatal(err) } creds := credentials.NewTLS(&tls.Config{ ServerName: "fgateway", RootCAs: certPool, }) cli, err := grpc.NewClient(gateway, g.WithTransportCredentials(creds)) if err != nil { log.Fatal(err) } http.HandleFunc("/api/invoke", func(w http.ResponseWriter, r *http.Request) { expr := r.Header.Get("X-Btrfaas-Chain") optionsStr := r.Header.Get("X-Btrfaas-Options") chain := strings.Split(expr, "|") options := [][]string{} if err := json.Unmarshal([]byte(optionsStr), &options); err != nil { w.WriteHeader(http.StatusBadRequest) return } buf := &bytes.Buffer{} if err := cli.Run(context.Background(), chain, options, r.Body, buf); err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error())) return } io.Copy(w, buf) }) assetDir, _ := cmd.Flags().GetString("assets") http.Handle("/", http.FileServer(http.Dir(assetDir))) listen, _ := cmd.Flags().GetString("listen") if err := http.ListenAndServe(listen, nil); err != nil { log.Fatal(err) } }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.