Skip to content

Commit

Permalink
Initialize stonks.icu
Browse files Browse the repository at this point in the history
  • Loading branch information
ericm committed May 25, 2020
1 parent 626b7fb commit 165f1d2
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -4,6 +4,10 @@ build:
go get
go build -v -o ${BINAME}

web:
go get
cd stonks.icu && go build -v -o ${BINAME}

install:
go install -v

Expand Down
8 changes: 8 additions & 0 deletions stonks.icu/config.go
@@ -0,0 +1,8 @@
package main

import "github.com/spf13/viper"

func configure() {
viper.SetDefault("port", 8080)
viper.AutomaticEnv()
}
27 changes: 27 additions & 0 deletions stonks.icu/entrypoint.go
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"net/http"
"strings"

"github.com/spf13/viper"
)

func main() {
configure()
http.HandleFunc("/", handleSymbol)
http.ListenAndServe(fmt.Sprintf(":%d", viper.GetInt("port")), nil)
}

func handleSymbol(w http.ResponseWriter, r *http.Request) {
symbols := strings.Split(r.URL.Path, "/")
if r.Header.Get("User-Agent") != "" {
w.Header().Add("Location", "https://github.com/ericm/stonks")
w.WriteHeader(302)
w.Write([]byte(" "))
}
for _, symbol := range symbols {
fmt.Println(symbol)
}
}
8 changes: 8 additions & 0 deletions stonks.icu/go.mod
@@ -0,0 +1,8 @@
module github.com/ericm/stonks/stonks.icu

go 1.14

require (
github.com/ericm/stonks v1.0.6
github.com/spf13/viper v1.7.0
)

0 comments on commit 165f1d2

Please sign in to comment.