-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from niontive/niontive/aks-poc-rp
Add Simple HTTP Server
- Loading branch information
Showing
7 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
package main | ||
|
||
import "github.com/sirupsen/logrus" | ||
import ( | ||
"context" | ||
"flag" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/Azure/ARO-RP/pkg/poc" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
func poc(log *logrus.Entry) error { | ||
func rpPoc(ctx context.Context, log *logrus.Entry) error { | ||
log.Print("********** ARO-RP on AKS PoC **********") | ||
return nil | ||
|
||
ctx, shutdown := context.WithCancel(ctx) | ||
defer shutdown() | ||
go handleSigterm(log, shutdown) | ||
|
||
port := flag.Arg(1) | ||
frontEnd := poc.NewFrontend(log, port) | ||
|
||
return frontEnd.Run(ctx) | ||
} | ||
|
||
func handleSigterm(log *logrus.Entry, shutdown context.CancelFunc) { | ||
signals := make(chan os.Signal, 1) | ||
signal.Notify(signals, syscall.SIGTERM) | ||
<-signals | ||
|
||
log.Print("received SIGTERM. Terminating...") | ||
|
||
shutdown() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package poc | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
type frontend struct { | ||
logger *logrus.Entry | ||
port string | ||
} | ||
|
||
func NewFrontend(logger *logrus.Entry, port string) frontend { | ||
return frontend{ | ||
logger: logger, | ||
port: port, | ||
} | ||
} | ||
|
||
func (f *frontend) Run(ctx context.Context) error { | ||
router := f.getRouter() | ||
server := &http.Server{ | ||
Addr: ":" + f.port, | ||
Handler: router, | ||
ErrorLog: log.New(f.logger.Writer(), "", 0), | ||
} | ||
|
||
go func() { | ||
f.logger.Info("Starting http server...") | ||
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
f.logger.Fatalf("Server listen/serve error: %s", err) | ||
} | ||
}() | ||
|
||
<-ctx.Done() | ||
|
||
f.logger.Info("Stopping http server") | ||
err := server.Shutdown(context.Background()) | ||
if err != nil { | ||
f.logger.Errorf("Server shutdown error: %s", err) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (f *frontend) getRouter() chi.Router { | ||
r := chi.NewRouter() | ||
r.Get("/", func(w http.ResponseWriter, r *http.Request) { | ||
f.logger.Infof("Received request: %s", time.Now().String()) | ||
w.Write([]byte("****** ARO-RP on AKS PoC ******")) | ||
}) | ||
return r | ||
} |
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
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
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