Created
April 28, 2010 11:37
-
-
Save jpic/382031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"http" | |
"regexp" | |
/*"io"*/ | |
"log" | |
"fcgi" | |
) | |
type Root struct { | |
Url string | |
Root string | |
} | |
type Site struct { | |
HostRegexp string | |
FcgiNode string | |
Roots []Root | |
} | |
type Configuration struct { | |
Address string | |
Sites []Site | |
} | |
var configuration = Configuration{ | |
"0.0.0.0:80", | |
[]Site{ | |
Site{ | |
"foo.com", | |
"tcp://127.0.0.1:9000", | |
[]Root{ | |
Root{ | |
"/site_media", | |
"/srv/music/site_media", | |
}, | |
}, | |
}, | |
}, | |
} | |
func (cfg *Configuration) ServeHTTP(c *http.Conn, req *http.Request) { | |
for _, site := range cfg.Sites { | |
match, _ := regexp.MatchString( site.HostRegexp, req.Host ) | |
if match { | |
handler, _ := fcgi.Handler([]fcgi.Dialer{ | |
fcgi.NewDialer("tcp", site.FcgiNode), | |
}) | |
fmt.Println("Serving") | |
handler.ServeHTTP(c, req) | |
return | |
} | |
} | |
} | |
func main() { | |
println("serving on", configuration.Address) | |
http.Handle("/", &configuration) | |
err := http.ListenAndServe(configuration.Address, nil) | |
if err != nil { | |
log.Exit("ListenAndServe:", err) | |
} | |
return | |
} | |
/* Error: | |
panic: runtime error: invalid memory address or nil pointer dereference | |
panic PC=0xb76aa0d0 | |
runtime.panic+0x97 /home/jpic/src/go/src/pkg/runtime/proc.c:1011 | |
runtime.panic(0x0, 0x80d1b48) | |
panicstring+0x5e /home/jpic/src/go/src/pkg/runtime/runtime.c:83 | |
panicstring(0x80d1b48, 0xb77200d8) | |
sigpanic+0x8f /home/jpic/src/go/src/pkg/runtime/linux/thread.c:285 | |
sigpanic() | |
main.*Configuration·ServeHTTP+0x212 /home/jpic/src/goserver/serve.go:36 | |
main.*Configuration·ServeHTTP(0x0, 0xb76a3780, 0xb76bb000, 0x8) | |
http.*ServeMux·ServeHTTP+0x207 /home/jpic/src/go/src/pkg/http/server.go:508 | |
http.*ServeMux·ServeHTTP(0x80e6464, 0xb76a3780, 0xb76bb000, 0x1) | |
http.*Conn·serve+0x73 /home/jpic/src/go/src/pkg/http/server.go:289 | |
http.*Conn·serve(0xb7697818, 0xb76a3780) | |
goexit /home/jpic/src/go/src/pkg/runtime/proc.c:145 | |
goexit() | |
goroutine 2 [3]: | |
runtime.entersyscall+0x5d /home/jpic/src/go/src/pkg/runtime/proc.c:562 | |
runtime.entersyscall() | |
syscall.Syscall6+0x5 /home/jpic/src/go/src/pkg/syscall/asm_linux_386.s:40 | |
syscall.Syscall6() | |
syscall.EpollWait+0x71 /home/jpic/src/go/src/pkg/syscall/zsyscall_linux_386.go:132 | |
syscall.EpollWait(0x100, 0x6, 0xb76ed8c0, 0x1, 0xffffffff, ...) | |
net.*pollster·WaitFD+0x111 /home/jpic/src/go/src/pkg/net/fd_linux.go:116 | |
net.*pollster·WaitFD(0x6, 0xb76ed8c0, 0x1, 0x1, 0xffffffff, ...) | |
net.*pollServer·Run+0xc9 /home/jpic/src/go/src/pkg/net/fd.go:232 | |
net.*pollServer·Run(0xb76978b8, 0x0) | |
goexit /home/jpic/src/go/src/pkg/runtime/proc.c:145 | |
goexit() | |
goroutine 1 [4]: | |
gosched+0x66 /home/jpic/src/go/src/pkg/runtime/proc.c:541 | |
gosched() | |
chanrecv+0x14b /home/jpic/src/go/src/pkg/runtime/chan.c:355 | |
chanrecv(0xb76a3370, 0xb76ef620, 0x1, 0x808df72) | |
runtime.chanrecv1+0x37 /home/jpic/src/go/src/pkg/runtime/chan.c:429 | |
runtime.chanrecv1(0xb76a3340, 0xb76a6db0) | |
net.*pollServer·WaitRead+0x4d /home/jpic/src/go/src/pkg/net/fd.go:272 | |
net.*pollServer·WaitRead(0xb76a3340, 0xb76a4f00, 0x0) | |
net.*netFD·accept+0x2c2 /home/jpic/src/go/src/pkg/net/fd.go:508 | |
net.*netFD·accept(0xb76ef740, 0xb76a4f00, 0x0, 0x0, 0xb, ...) | |
net.*TCPListener·AcceptTCP+0x53 /home/jpic/src/go/src/pkg/net/tcpsock.go:253 | |
net.*TCPListener·AcceptTCP(0xb76a4f00, 0x8094e21, 0x0, 0x0) | |
net.*TCPListener·Accept+0x36 /home/jpic/src/go/src/pkg/net/tcpsock.go:263 | |
net.*TCPListener·Accept(0xb7697860, 0xb76a6f40, 0x0, 0x0, 0xb7697a50, ...) | |
http.Serve+0x6b /home/jpic/src/go/src/pkg/http/server.go:551 | |
http.Serve(0xb7697860, 0x0, 0x0, 0x0, 0x0, ...) | |
http.ListenAndServe+0x84 /home/jpic/src/go/src/pkg/http/server.go:596 | |
http.ListenAndServe(0xb76ef680, 0xb7697860, 0xb76ef660, 0xb7697818, 0xb76ef680, ...) | |
main.main+0xa3 /home/jpic/src/goserver/serve.go:47 | |
main.main() | |
mainstart+0xf /home/jpic/src/go/src/pkg/runtime/386/asm.s:83 | |
mainstart() | |
goexit /home/jpic/src/go/src/pkg/runtime/proc.c:145 | |
goexit() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment