Skip to content

Commit

Permalink
Merge pull request #3 from ikotun-dev/rewrite-config
Browse files Browse the repository at this point in the history
Minor cleanups
  • Loading branch information
ikotun-dev authored May 2, 2024
2 parents 599a226 + 454296f commit 3e4f935
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 16 deletions.
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ module github.com/ikotun-dev/warp
go 1.22.0

require (
github.com/chromedp/cdproto v0.0.0-20240202021202-6d0b6a386732 // indirect
github.com/chromedp/chromedp v0.9.5 // indirect
github.com/chromedp/sysutil v1.0.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.3.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
golang.org/x/sys v0.16.0 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
github.com/chromedp/cdproto v0.0.0-20240202021202-6d0b6a386732 h1:XYUCaZrW8ckGWlCRJKCSoh/iFwlpX316a8yY9IFEzv8=
github.com/chromedp/cdproto v0.0.0-20240202021202-6d0b6a386732/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.5 h1:viASzruPJOiThk7c5bueOUY91jGLJVximoEMGoH93rg=
github.com/chromedp/chromedp v0.9.5/go.mod h1:D4I2qONslauw/C7INoCir1BJkSwBYMyZgx8X276z3+Y=
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.3.2 h1:zlnbNHxumkRvfPWgfXu8RBwyNR1x8wh9cf5PTOCqs9Q=
github.com/gobwas/ws v1.3.2/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
Expand Down
7 changes: 4 additions & 3 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"
"path/filepath"

Expand All @@ -23,11 +24,11 @@ func MockConfig() *Config {
}

func InitConfig() *Config {
if _, err := os.Stat("../config.yaml"); os.IsNotExist(err) {
if _, err := os.Stat("../warp.yaml"); os.IsNotExist(err) {
return MockConfig()
}
var err error
config, err = ReadConfig("../config.yaml")
config, err = ReadConfig("../warp.yaml")
if err != nil {
fmt.Println("Error : ", err)
}
Expand All @@ -44,7 +45,7 @@ func ReadConfig(filename string) (*Config, error) {
fmt.Printf("yamlFile.Get err #%v ", err)
}

fmt.Println("YAML file contents:", string(yamlFile))
log.Println("Successfully read configuration file.")

err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
Expand Down
Binary file modified pkg/pkg
Binary file not shown.
15 changes: 3 additions & 12 deletions pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,24 @@ import (
)

var config *Config

var mimeType string

var filePath string

func serveStaticFile(w http.ResponseWriter, r *http.Request) {
//TODO: handle rewrites, 404

if config == nil {
http.Error(w, "Configuration not initialized", http.StatusInternalServerError)
return
}

//TODO: Loggin option in the config yaml

filePath = "../public" + r.URL.Path

_, err := os.Stat(filePath)
defaultPath := filepath.Join("../public", config.RootDir)

if err != nil {
//TRYING TO SEE WHAT I CAN DO FOR THE 404 STUFF
//
filePath = config.RootDir
log.Printf("LOG: I no see the file : %s", r.URL.Path)
log.Printf("Rewriting to root file : %s", r.URL.Path)
http.ServeFile(w, r, defaultPath)
}

Expand All @@ -57,9 +50,7 @@ func main() {

http.HandleFunc("/", serveStaticFile)

configPort := ":" + config.Port

fmt.Println("PORT : ", configPort)
fmt.Println("Warp server running on : ", config.Port)

log.Fatal(http.ListenAndServe(configPort, nil))
log.Fatal(http.ListenAndServe(":"+config.Port, nil))
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion config.yaml → warp.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
port: 8000
port: 3000
fallbackDocument: index.html
root: index.html

0 comments on commit 3e4f935

Please sign in to comment.