-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First implementation for two endpoints. #1
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8fbf517
Init implementation for two endpoints.
sgmv 60d2e9a
small fixes
sgmv 6384265
add migrations
sgmv 10d429b
incident creation
sgmv 95cca54
incident creation and openapi schema
sgmv a5c4ee6
fix linter issues
sgmv 9678fcc
fix linter issues
sgmv 92c4ad6
added error handler, small refactoring
sgmv db866e6
fix linter issues
sgmv e5ca704
added error handler and log, added new endpoint
sgmv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
# Exampe for environment variables | ||
SD_DB=postgresql://pg:pass@localhost:5432/status_dashboard | ||
SD_CACHE=internal | ||
#SD_LOG_LEVEL=devel |
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,24 @@ | ||
name: golangci-lint | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.60.3 |
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,10 @@ | ||
.idea | ||
*.bkp | ||
*.exe | ||
bin/ | ||
/pkg/ | ||
*.backup | ||
*.log | ||
*.bak | ||
*.test | ||
*.txt |
Large diffs are not rendered by default.
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,25 @@ | ||
default: test | ||
|
||
SHELL=/bin/bash | ||
|
||
SD_DB?="postgresql://pg:pass@localhost:5432/status_dashboard?sslmode=disable" | ||
|
||
test: | ||
@echo running tests | ||
go test ./... -count 1 | ||
|
||
build: | ||
@echo build app | ||
go build -o app cmd/main.go | ||
|
||
lint: | ||
@echo running linter | ||
golangci-lint run -v | ||
|
||
migrate-up: | ||
@echo staring migrations | ||
migrate -database $(SD_DB) -path db/migrations up | ||
|
||
migrate-down: | ||
@echo revert migrations | ||
migrate -database $(SD_DB) -path db/migrations down |
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"log" | ||
"net/http" | ||
"os/signal" | ||
"syscall" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/stackmon/otc-status-dashboard/internal/app" | ||
"github.com/stackmon/otc-status-dashboard/internal/conf" | ||
) | ||
|
||
func main() { | ||
c, err := conf.LoadConf() | ||
if err != nil { | ||
log.Fatalf("failed to parse configuration: %s", err.Error()) | ||
} | ||
|
||
logger := conf.NewLogger(c.LogLevel) | ||
logger.Info("app starting") | ||
|
||
s, err := app.New(c, logger) | ||
if err != nil { | ||
logger.Fatal("fail to init app", zap.Error(err)) | ||
} | ||
|
||
ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) | ||
defer done() | ||
|
||
go func() { | ||
if err = s.Run(); err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
logger.Fatal("app is failed to run", zap.Error(err)) | ||
} | ||
}() | ||
|
||
<-ctx.Done() | ||
s.Log.Info("shutdown app") | ||
|
||
if err = s.Shutdown(ctx); err != nil { | ||
logger.Fatal("app shutdown failed", zap.Error(err)) | ||
} | ||
|
||
logger.Info("app exited") | ||
} |
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,7 @@ | ||
DROP table if exists component cascade; | ||
DROP table if exists component_attribute cascade ; | ||
DROP table if exists incident cascade ; | ||
DROP table if exists incident_component_relation cascade ; | ||
DROP table if exists incident_status cascade ; | ||
|
||
DROP type if exists incidentimpactenum; |
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,59 @@ | ||
CREATE TYPE incidentimpactenum AS ENUM ( | ||
'maintenance', | ||
'minor', | ||
'major', | ||
'outage' | ||
); | ||
|
||
CREATE TABLE if not exists component ( | ||
id serial primary key, | ||
name character varying NOT NULL | ||
); | ||
|
||
CREATE INDEX ix_component_id ON component USING btree (id); | ||
|
||
CREATE TABLE if not exists component_attribute ( | ||
id serial primary key, | ||
component_id integer, | ||
name character varying NOT NULL, | ||
value character varying NOT NULL | ||
); | ||
|
||
CREATE INDEX ix_component_attribute_component_id ON component_attribute USING btree (component_id); | ||
CREATE INDEX ix_component_attribute_id ON component_attribute USING btree (id); | ||
|
||
CREATE TABLE if not exists incident ( | ||
id serial primary key, | ||
text character varying NOT NULL, | ||
start_date timestamp without time zone NOT NULL, | ||
end_date timestamp without time zone, | ||
impact smallint NOT NULL, | ||
system boolean DEFAULT false NOT NULL | ||
); | ||
|
||
CREATE INDEX ix_incident_id ON incident USING btree (id); | ||
|
||
CREATE TABLE if not exists incident_component_relation ( | ||
incident_id integer NOT NULL, | ||
component_id integer NOT NULL | ||
); | ||
|
||
CREATE UNIQUE INDEX inc_comp_rel ON incident_component_relation USING btree (incident_id, component_id); | ||
|
||
CREATE TABLE if not exists incident_status ( | ||
id serial primary key, | ||
incident_id integer, | ||
"timestamp" timestamp without time zone NOT NULL, | ||
text character varying NOT NULL, | ||
status character varying NOT NULL | ||
); | ||
|
||
CREATE INDEX ix_incident_status_id ON incident_status USING btree (id); | ||
CREATE INDEX ix_incident_status_incident_id ON incident_status USING btree (incident_id); | ||
|
||
|
||
ALTER TABLE ONLY component_attribute | ||
ADD CONSTRAINT component_attribute_component_id_fkey FOREIGN KEY (component_id) REFERENCES component(id); | ||
|
||
ALTER TABLE ONLY incident_component_relation | ||
ADD CONSTRAINT incident_component_relation_component_id_fkey FOREIGN KEY (component_id) REFERENCES component(id); |
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,18 @@ | ||
version: "3.8" | ||
|
||
services: | ||
database: | ||
container_name: database | ||
image: postgres:15.8 | ||
restart: always | ||
environment: | ||
- POSTGRES_USER=pg | ||
- POSTGRES_PASSWORD=pass | ||
- POSTGRES_DB=status_dashboard | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- db:/var/lib/postgresql/data | ||
|
||
volumes: | ||
db: |
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,55 @@ | ||
module github.com/stackmon/otc-status-dashboard | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/DATA-DOG/go-sqlmock v1.5.2 | ||
github.com/gin-gonic/gin v1.10.0 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/kelseyhightower/envconfig v1.4.0 | ||
github.com/stretchr/testify v1.9.0 | ||
go.uber.org/zap v1.27.0 | ||
gorm.io/driver/postgres v1.5.9 | ||
gorm.io/gorm v1.25.12 | ||
moul.io/zapgorm2 v1.3.0 | ||
) | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.12.1 // indirect | ||
github.com/bytedance/sonic/loader v0.2.0 // indirect | ||
github.com/cloudwego/base64x v0.1.4 // indirect | ||
github.com/cloudwego/iasm v0.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.22.0 // indirect | ||
github.com/goccy/go-json v0.10.3 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect | ||
github.com/jackc/pgx/v5 v5.6.0 // indirect | ||
github.com/jackc/puddle/v2 v2.2.1 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.8 // indirect | ||
github.com/leodido/go-urn v1.4.0 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rogpeppe/go-internal v1.12.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.12 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/arch v0.9.0 // indirect | ||
golang.org/x/crypto v0.26.0 // indirect | ||
golang.org/x/net v0.28.0 // indirect | ||
golang.org/x/sync v0.8.0 // indirect | ||
golang.org/x/sys v0.24.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add for CI:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the SHELL variable, but PATH under discussion :) We will use actions, so maybe we don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, lint checks work fine without additional PATH. I'll check it with unit tests.