-
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.
- Loading branch information
0 parents
commit 4c52a22
Showing
20 changed files
with
951 additions
and
0 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,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${fileDirname}", | ||
"env": {}, | ||
"args": [] | ||
} | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"go.useLanguageServer": true, | ||
"[go]": { | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": true, | ||
}, | ||
// Optional: Disable snippets, as they conflict with completion ranking. | ||
"editor.snippetSuggestions": "none", | ||
}, | ||
"[go.mod]": { | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": true, | ||
}, | ||
}, | ||
"gopls": { | ||
// Add parameter placeholders when completing a function. | ||
"usePlaceholders": true, | ||
|
||
// If true, enable additional analyses with staticcheck. | ||
// Warning: This will significantly increase memory usage. | ||
"staticcheck": false, | ||
} | ||
} |
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,68 @@ | ||
package controller | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/adesokanayo/innovation/entity" | ||
"github.com/adesokanayo/innovation/errors" | ||
"github.com/adesokanayo/innovation/services" | ||
) | ||
|
||
type controller struct{} | ||
|
||
//NewPostController creates a controller instance | ||
func NewPostController() PostController { | ||
return &controller{} | ||
} | ||
|
||
var ( | ||
postService services.PostService = services.NewPostService() | ||
) | ||
|
||
//PostController is | ||
type PostController interface { | ||
GetPosts(response http.ResponseWriter, request *http.Request) | ||
AddPosts(response http.ResponseWriter, request *http.Request) | ||
} | ||
|
||
//GetPosts retrieve all posts | ||
func (*controller) GetPosts(resp http.ResponseWriter, req *http.Request) { | ||
resp.Header().Set("Content-type", "application/json") | ||
|
||
posts, err := postService.FindAll() | ||
if err != nil { | ||
resp.WriteHeader(http.StatusInternalServerError) | ||
json.NewEncoder(resp).Encode(errors.ServiceError{"Error getting the post"}) | ||
} | ||
resp.WriteHeader(http.StatusOK) | ||
json.NewEncoder(resp).Encode(posts) | ||
|
||
} | ||
|
||
func (*controller) AddPosts(resp http.ResponseWriter, req *http.Request) { | ||
resp.Header().Set("Content-type", "application/json") | ||
var post entity.Post | ||
err := json.NewDecoder(req.Body).Decode(&post) | ||
if err != nil { | ||
resp.WriteHeader(http.StatusInternalServerError) | ||
json.NewEncoder(resp).Encode(errors.ServiceError{Message: "Error adding the posts"}) | ||
return | ||
} | ||
|
||
err1 := postService.Validate(&post) | ||
if err1 != nil { | ||
resp.WriteHeader(http.StatusInternalServerError) | ||
json.NewEncoder(resp).Encode(errors.ServiceError{Message: err1.Error()}) | ||
return | ||
} | ||
result, err2 := postService.Create(&post) | ||
if err2 != nil { | ||
resp.WriteHeader(http.StatusInternalServerError) | ||
json.NewEncoder(resp).Encode(errors.ServiceError{Message: err2.Error()}) | ||
return | ||
} | ||
postService.Create(&post) | ||
resp.WriteHeader(http.StatusOK) | ||
json.NewEncoder(resp).Encode(result) | ||
} |
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,33 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-go-app | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: go-app | ||
template: | ||
metadata: | ||
labels: | ||
app: go-app | ||
spec: | ||
containers: | ||
- name: go-app-container | ||
image: adesokanayo/go-api-img:1.0.0 | ||
volumeMounts: | ||
- name: storage | ||
mountPath: temp/keys/ | ||
resources: | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
ports: | ||
- containerPort: 3000 | ||
securityContext: | ||
capabilities: | ||
add: ["SYS_ADMIN"] | ||
volumes: | ||
- name: storage | ||
emptyDir: {} | ||
|
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,16 @@ | ||
FROM golang:alpine as builder | ||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* | ||
LABEL name=Ayo | ||
LABEL [email protected] | ||
RUN mkdir /app | ||
WORKDIR /app | ||
COPY . . | ||
|
||
RUN go get . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . | ||
RUN apk add --no-cache ca-certificates | ||
FROM scratch | ||
WORKDIR /home/innovation | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /app . | ||
CMD ["./app"] |
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,8 @@ | ||
package entity | ||
|
||
//Post holds the definition of a Post item | ||
type Post struct { | ||
ID int64 `json:"id"` | ||
Title string `json:"title"` | ||
Text string `json:"text"` | ||
} |
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 errors | ||
|
||
type ServiceError struct { | ||
Message string `json:message` | ||
} |
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 @@ | ||
module Users/odunayo/Desktop/innovation | ||
|
||
go 1.15 | ||
|
||
require github.com/stretchr/testify v1.6.1 |
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 @@ | ||
module github.com/adesokanayo/innovation | ||
|
||
go 1.15 |
Oops, something went wrong.