Http server ready!
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*.log
|
||||
*.pid
|
||||
|
||||
56
main.go
Normal file
56
main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/sevlyar/go-daemon"
|
||||
"gitlab.com/saburly/kiviscraplib/structures"
|
||||
"gitlab.com/saburly/kiviscraplib/webserver"
|
||||
"log"
|
||||
)
|
||||
|
||||
var queue chan structures.Request
|
||||
var end chan string
|
||||
|
||||
// To terminate the daemon use:
|
||||
// kill `cat sample.pid`
|
||||
func main() {
|
||||
cntxt := &daemon.Context{
|
||||
PidFileName: "sample.pid",
|
||||
PidFilePerm: 0644,
|
||||
LogFileName: "sample.log",
|
||||
LogFilePerm: 0640,
|
||||
WorkDir: "./",
|
||||
Umask: 027,
|
||||
Args: []string{"[kivi scraping load balancer]"},
|
||||
}
|
||||
|
||||
d, err := cntxt.Reborn()
|
||||
if err != nil {
|
||||
log.Fatal("Unable to run: ", err)
|
||||
}
|
||||
if d != nil {
|
||||
return
|
||||
}
|
||||
defer cntxt.Release()
|
||||
|
||||
// todo: put queue length in env variable
|
||||
queue = make(chan structures.Request, 1000)
|
||||
end = make(chan string)
|
||||
|
||||
go webserver.ServeHTTP(queue, end)
|
||||
go func() {
|
||||
for {
|
||||
request := <-queue
|
||||
//time.Sleep(2 * time.Second)
|
||||
response := structures.Response{
|
||||
Url: request.Url,
|
||||
Content: []byte("<html><body><h1>Bla!</h1></body><html>"),
|
||||
Err: nil,
|
||||
}
|
||||
request.Response <- response
|
||||
}
|
||||
}()
|
||||
|
||||
ended := <-end
|
||||
|
||||
log.Printf("%s ended so closing the daemon", ended)
|
||||
}
|
||||
Reference in New Issue
Block a user