Move RnD sample programs to examples dir, rename test_data to example_data, add stubs for server and client
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"doll/internal/doll"
|
||||
"doll/internal/log"
|
||||
"os"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Init("info", os.Stderr)
|
||||
log.Info("loading 01-config.json")
|
||||
|
||||
data := doll.LoadJsonFile("test_data/01-config.json")
|
||||
|
||||
log.Info("data from 01-config.json is")
|
||||
spew.Dump(data)
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
@@ -1,36 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"doll/internal/log"
|
||||
"os"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Init("info", os.Stderr)
|
||||
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
// Load the Lua script file.
|
||||
log.Info("Loading ./test_data/02-test.lua")
|
||||
|
||||
// We can execute script directly via L.DoFile("./test_data/02-test.lua") but in practice we'll get scripts as
|
||||
// strings - snippets from templates - so, testing/checking how it works is not use for project.
|
||||
luaCode, err := os.ReadFile("./test_data/02-test.lua")
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Error reading Lua file: %s", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := L.DoString(string(luaCode)); err != nil {
|
||||
log.Errorf("Error evaluating Lua code: %s", err)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
23
cmd/doll-master/main.go
Normal file
23
cmd/doll-master/main.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"doll/internal/log"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Register http-request handler.
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Doll-master here!")
|
||||
})
|
||||
|
||||
// And run server on 8240 port.
|
||||
log.Info("Starting server at port 8240")
|
||||
|
||||
if err := http.ListenAndServe(":8240", nil); err != nil {
|
||||
log.Fatalf("Error starting the server: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
26
cmd/doll/main.go
Normal file
26
cmd/doll/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"doll/internal/log"
|
||||
|
||||
"github.com/carlmjohnson/requests"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
body string
|
||||
userAgent = "doll"
|
||||
url = "http://localhost:8240/"
|
||||
err error
|
||||
)
|
||||
|
||||
if err = requests.URL(url).UserAgent(userAgent).ToString(&body).Fetch(ctx); err != nil {
|
||||
log.Fatalf("unable to GET %s: %s", url, err)
|
||||
}
|
||||
|
||||
log.Infof("Response is: %s", body)
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
Reference in New Issue
Block a user