cleanup
This commit is contained in:
parent
59f23c19a8
commit
8cb0debf32
39
gopher.go
Normal file
39
gopher.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/prologic/go-gopher"
|
||||
)
|
||||
|
||||
type GopherConfig struct {
|
||||
Hostname string
|
||||
Port string
|
||||
RootDir string
|
||||
}
|
||||
|
||||
func (c *GopherConfig) String() string {
|
||||
return fmt.Sprintf("Gopher Config: %v:%v Files:%v", c.Hostname, c.Port, c.RootDir)
|
||||
}
|
||||
|
||||
type indexHandler struct {
|
||||
rootPath string
|
||||
rootHandler gopher.Handler
|
||||
}
|
||||
|
||||
func (f *indexHandler) ServeGopher(w gopher.ResponseWriter, r *gopher.Request) {
|
||||
upath := r.Selector
|
||||
if gopher.GetItemType(f.rootPath+upath) == gopher.DIRECTORY && upath != "/" {
|
||||
w.WriteItem(&gopher.Item{
|
||||
Type: gopher.DIRECTORY,
|
||||
Selector: path.Dir(upath),
|
||||
Description: "Go Back",
|
||||
})
|
||||
}
|
||||
f.rootHandler.ServeGopher(w, r)
|
||||
}
|
||||
|
||||
func index(root gopher.FileSystem) *indexHandler {
|
||||
return &indexHandler{root.Name(), gopher.FileServer(root)}
|
||||
}
|
46
main.go
46
main.go
@ -1,9 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"github.com/prologic/go-gopher"
|
||||
@ -53,7 +51,6 @@ func main() {
|
||||
go func(h interface{}) {
|
||||
hole := h.(GopherConfig)
|
||||
gopher.Handle("/", index(gopher.Dir(hole.RootDir)))
|
||||
//log.Fatal(gopher.ListenAndServe(hole.Hostname+":"+hole.Port, nil))
|
||||
server := &gopher.Server{Addr: "0.0.0.0:" + hole.Port, Hostname: hole.Hostname, Handler: nil}
|
||||
log.Fatal(server.ListenAndServe())
|
||||
wg.Done()
|
||||
@ -63,46 +60,3 @@ func main() {
|
||||
log.Println("Ho ho! You found me!")
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
type GeminiConfig struct {
|
||||
Hostname string
|
||||
Port string
|
||||
KeyFile string
|
||||
CertFile string
|
||||
RootDir string
|
||||
CGIDir string
|
||||
}
|
||||
|
||||
type GopherConfig struct {
|
||||
Hostname string
|
||||
Port string
|
||||
RootDir string
|
||||
}
|
||||
|
||||
func (c *GeminiConfig) String() string {
|
||||
return fmt.Sprintf("Gemini Config: %v:%v Files:%v CGI:%v", c.Hostname, c.Port, c.RootDir, c.CGIDir)
|
||||
}
|
||||
func (c *GopherConfig) String() string {
|
||||
return fmt.Sprintf("Gopher Config: %v:%v Files:%v", c.Hostname, c.Port, c.RootDir)
|
||||
}
|
||||
|
||||
type indexHandler struct {
|
||||
rootPath string
|
||||
rootHandler gopher.Handler
|
||||
}
|
||||
|
||||
func (f *indexHandler) ServeGopher(w gopher.ResponseWriter, r *gopher.Request) {
|
||||
upath := r.Selector
|
||||
if gopher.GetItemType(f.rootPath+upath) == gopher.DIRECTORY && upath != "/" {
|
||||
w.WriteItem(&gopher.Item{
|
||||
Type: gopher.DIRECTORY,
|
||||
Selector: path.Dir(upath),
|
||||
Description: "Go Back",
|
||||
})
|
||||
}
|
||||
f.rootHandler.ServeGopher(w, r)
|
||||
}
|
||||
|
||||
func index(root gopher.FileSystem) *indexHandler {
|
||||
return &indexHandler{root.Name(), gopher.FileServer(root)}
|
||||
}
|
||||
|
15
proto.go
15
proto.go
@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Yoinked from jetforce and go'ified
|
||||
const (
|
||||
STATUS_INPUT = 10
|
||||
@ -35,3 +37,16 @@ type Response struct {
|
||||
Meta string
|
||||
Body string
|
||||
}
|
||||
|
||||
type GeminiConfig struct {
|
||||
Hostname string
|
||||
Port string
|
||||
KeyFile string
|
||||
CertFile string
|
||||
RootDir string
|
||||
CGIDir string
|
||||
}
|
||||
|
||||
func (c *GeminiConfig) String() string {
|
||||
return fmt.Sprintf("Gemini Config: %v:%v Files:%v CGI:%v", c.Hostname, c.Port, c.RootDir, c.CGIDir)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user