-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nlayared web application support added
- Loading branch information
Showing
72 changed files
with
1,212 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
variables: | ||
DOCKER_HOST: tcp://docker:2375/ | ||
|
||
stages: | ||
- build | ||
- test | ||
- package | ||
- prepare-test-artifacts | ||
- deploy-to-test-env | ||
- pact-provider-verify | ||
- prepare-prod-artifacts | ||
- deploy-to-prod-env | ||
|
||
build: | ||
stage: build | ||
image: golang:1.17.0-alpine3.14 | ||
before_script: | ||
- go mod tidy -go=1.16 && go mod tidy -go=1.17 | ||
script: | ||
- go build -o bin/main main.go | ||
|
||
test: | ||
stage: test | ||
image: golang:1.17 | ||
variables: | ||
CI : $CI | ||
before_script: | ||
- go mod tidy -go=1.16 && go mod tidy -go=1.17 | ||
script: | ||
- go test | ||
|
||
package: | ||
stage: package | ||
image: docker:18-git | ||
services: | ||
- name: docker:18-dind | ||
variables: | ||
DOCKER_REGISTRY_NAME: $MY_CI_REGISTRY_NAME:$CI_PIPELINE_ID | ||
script: | ||
- docker login -u $MY_CI_DOCKER_USER --password $MY_CI_DOCKER_PASS | ||
- docker build -t $DOCKER_REGISTRY_NAME $CI_PROJECT_DIR | ||
- docker push $DOCKER_REGISTRY_NAME |
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,3 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment |
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,3 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim |
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,3 @@ | ||
--- | ||
apiVersion: storage.k8s.io/v1 | ||
kind: StorageClass |
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,3 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service |
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,3 @@ | ||
--- | ||
technology: | ||
config_name: value |
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,3 @@ | ||
--- | ||
technology: | ||
config_name: value |
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,3 @@ | ||
--- | ||
technology: | ||
config_name: value |
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,3 @@ | ||
--- | ||
technology: | ||
config_name: value |
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,5 @@ | ||
package main | ||
|
||
func main() { | ||
|
||
} |
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
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 was deleted.
Oops, something went wrong.
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,77 @@ | ||
package web | ||
|
||
import ( | ||
logger "<path-to-core>/logger" | ||
middleware "<path-to-core>/middleware" | ||
router "<path-to-core>/router" | ||
"context" | ||
"encoding/gob" | ||
"errors" | ||
"html/template" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
type Service interface { | ||
GetUsers(ctx context.Context, limit int) | ||
} | ||
type Renderer interface { | ||
Render(w http.ResponseWriter, tmpl *template.Template, data any, statusCode int) | ||
} | ||
|
||
type Handler struct { | ||
handler http.Handler | ||
logger logger.Logger | ||
renderer Renderer | ||
service Service | ||
templates PageTemplates | ||
urlParamExtractor func(ctx context.Context, key string) string | ||
} | ||
|
||
func NewHandler(logger logger.Logger, service Service, renderer Renderer) *Handler { | ||
if logger == nil { | ||
return nil | ||
} | ||
if session == nil || service == nil || renderer == nil { | ||
logger.Error("invalid arguments")) | ||
return nil | ||
} | ||
handler := Handler{logger: logger, service: service, renderer: renderer} | ||
|
||
handler.init() | ||
|
||
return &handler | ||
} | ||
func (h *Handler) init() { | ||
muxRouter := router.NewMuxRouterAdapter() | ||
h.urlParamExtractor = muxRouter.ExtractURLParam | ||
h.handler = muxRouter | ||
h.RegisterHandlers(muxRouter) | ||
|
||
h.applyMiddlewares() | ||
|
||
gob.Register(url.Values{}) | ||
|
||
templates := make(PageTemplates, 0) | ||
templates["home"] = ParseTemplate("home.gohtml") | ||
h.templates = templates | ||
} | ||
func (h *Handler) applyMiddlewares() { | ||
//apply method overriding middleware | ||
h.handler = middleware.OverrideFormMethods(h.handler) | ||
} | ||
|
||
func (h *Handler) RenderPage(page string, w http.ResponseWriter, data any, statusCode int) { | ||
h.renderer.Render(w, h.templates[page], data, statusCode) | ||
} | ||
|
||
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | ||
h.handler.ServeHTTP(w, req) | ||
} | ||
|
||
func (h *Handler) RegisterHandlers(muxRouter router.Router) { | ||
muxRouter.Handle("/", router.MethodHandlers{ | ||
http.MethodGet: h.ShowHome, | ||
}) | ||
|
||
} |
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,17 @@ | ||
package web | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type homeData struct { | ||
Header string | ||
} | ||
|
||
func (h *Handler) ShowHome(w http.ResponseWriter, r *http.Request) { | ||
h.RenderHome(w, homeData{Header: "Welcome"}, http.StatusFound) | ||
} | ||
|
||
func (h *Handler) RenderHome(w http.ResponseWriter, data homeData, status int) { | ||
h.RenderPage("home", w, data, status) | ||
} |
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,3 @@ | ||
<div> | ||
<h1>{{.Header}}</h1> | ||
</div> |
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,9 @@ | ||
This directory contains common ui elements | ||
like reusable components and layout elements which | ||
are common for every page. | ||
|
||
Suppose that you want to render home.gohtml page | ||
then actually the html content of home.gohtml | ||
taken by template engine and get put into layout.gohtml | ||
file which expects a template "content". Every page | ||
you want to parse and render, the same thing continually happens. |
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,3 @@ | ||
<nav> | ||
|
||
</nav> |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Softdare</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
{{template "header.gohtml" .}} | ||
{{template "content" .}} | ||
</body> | ||
|
||
</html> |
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,20 @@ | ||
package web | ||
|
||
import ( | ||
coreTemplate "<path-to-core>/html/template" | ||
"embed" | ||
"html/template" | ||
) | ||
|
||
//go:embed template/include/*.gohtml template/*.gohtml | ||
|
||
var templateFS embed.FS | ||
|
||
var templateFuncs = template.FuncMap{ | ||
"linkify": coreTemplate.Linkify, | ||
} | ||
|
||
func ParseTemplate(name string) *template.Template { | ||
return coreTemplate.Parse(name, templateFuncs, templateFS, | ||
"template/include/*.gohtml", "template/") | ||
} |
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,5 @@ | ||
package web | ||
|
||
import "html/template" | ||
|
||
type PageTemplates map[string]*template.Template |
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 @@ | ||
package httpclient |
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 @@ | ||
package httpclient_test |
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 @@ | ||
package rabbitclient |
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 @@ | ||
package rabbitclient_test |
Oops, something went wrong.