init
This commit is contained in:
commit
2e6d1f1e48
|
@ -0,0 +1,17 @@
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
|
.idea
|
|
@ -0,0 +1,3 @@
|
||||||
|
module gitea.dwysokinski.me/Kichiyaki/notificationarr
|
||||||
|
|
||||||
|
go 1.18
|
|
@ -0,0 +1,4 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
type Notification struct {
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultPort = "9234"
|
||||||
|
readTimeout = 2 * time.Second
|
||||||
|
readHeaderTimeout = 2 * time.Second
|
||||||
|
writeTimeout = 2 * time.Second
|
||||||
|
idleTimeout = 2 * time.Second
|
||||||
|
serverShutdownTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
srv := newServer()
|
||||||
|
|
||||||
|
go func(srv *http.Server) {
|
||||||
|
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Fatalln("srv.ListenAndServe:", err)
|
||||||
|
}
|
||||||
|
}(srv)
|
||||||
|
|
||||||
|
log.Println("Server is listening on the port", defaultPort)
|
||||||
|
|
||||||
|
waitForSignal(context.Background())
|
||||||
|
|
||||||
|
ctxShutdown, cancelShutdown := context.WithTimeout(context.Background(), serverShutdownTimeout)
|
||||||
|
defer cancelShutdown()
|
||||||
|
err := srv.Shutdown(ctxShutdown)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("srv.Shutdown:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newServer() *http.Server {
|
||||||
|
return &http.Server{
|
||||||
|
Addr: ":" + defaultPort,
|
||||||
|
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, _ = io.Copy(os.Stdout, r.Body)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}),
|
||||||
|
ReadTimeout: readTimeout,
|
||||||
|
ReadHeaderTimeout: readHeaderTimeout,
|
||||||
|
WriteTimeout: writeTimeout,
|
||||||
|
IdleTimeout: idleTimeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForSignal(ctx context.Context) {
|
||||||
|
ctx, stop := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
|
||||||
|
defer stop()
|
||||||
|
<-ctx.Done()
|
||||||
|
}
|
Reference in New Issue