From f69a850bd80b967b9eedb7b240b01ad54d04db97 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Fri, 23 May 2025 21:38:07 -0600 Subject: [PATCH] got a silly ui that can yield a test token --- src/bank/teller/application_id.txt | 1 + src/bank/teller/init.go | 56 ++++++++++++++++++++++++++++- src/bank/teller/init.html | 58 ++++++++++++++++++++++++++++++ src/bank/teller/token.txt | 1 + 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/bank/teller/application_id.txt create mode 100644 src/bank/teller/init.html diff --git a/src/bank/teller/application_id.txt b/src/bank/teller/application_id.txt new file mode 100644 index 0000000..3c61bf0 --- /dev/null +++ b/src/bank/teller/application_id.txt @@ -0,0 +1 @@ +app_pdvv33dtmta4fema66000 \ No newline at end of file diff --git a/src/bank/teller/init.go b/src/bank/teller/init.go index 5a8aa2a..4eb5975 100644 --- a/src/bank/teller/init.go +++ b/src/bank/teller/init.go @@ -3,18 +3,72 @@ package teller import ( "bufio" "context" + _ "embed" "fmt" + "io" + "net/http" "os" + "slices" "strings" + "text/template" +) + +var ( + //go:embed application_id.txt + applicationId string + //go:embed init.html + initHTML string ) func Init(ctx context.Context) error { + reader := bufio.NewReader(os.Stdin) + if Token == "" { - } else if reader := bufio.NewReader(os.Stdin); false { } else if fmt.Println("Token already exists; are you sure [nY]?"); false { } else if text, _ := reader.ReadString('\n'); !strings.Contains(text, "Y") { return fmt.Errorf("token already exists") } + environment := "development" + if sandbox := !slices.Contains(os.Args, "forreal"); sandbox { + environment = "sandbox" + } + fmt.Printf("environment=%q\n", environment) + + newTokens := make(chan string) + defer close(newTokens) + s := &http.Server{ + Addr: ":20000", + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + b, _ := io.ReadAll(r.Body) + newTokens <- string(b) + return + } + + t, err := template.New("initHTML").Parse(initHTML) + if err != nil { + panic(err) + } + + if err := t.Execute(w, map[string]string{ + "applicationId": applicationId, + "environment": environment, + }); err != nil { + panic(err) + } + }), + } + defer s.Close() + go s.ListenAndServe() + + fmt.Println("Open https://localhost:20000") + + select { + case <-ctx.Done(): + case newToken := <-newTokens: + return fmt.Errorf("not impl: %q => token.txt", newToken) + } + return ctx.Err() } diff --git a/src/bank/teller/init.html b/src/bank/teller/init.html new file mode 100644 index 0000000..1cae28d --- /dev/null +++ b/src/bank/teller/init.html @@ -0,0 +1,58 @@ + +
+ + + +