Browse Source

Adds drone config, fixes linting errors

master
Noah Pederson 3 years ago
parent
commit
2d5bd33c97
  1. 45
      .drone.yml
  2. 2
      cmd/main.go
  3. 5
      go.mod
  4. 10
      go.sum
  5. 14
      pkg/contact/contact.go
  6. 3
      pkg/contact/web.go

45
.drone.yml

@ -0,0 +1,45 @@
kind: pipeline
name: default
steps:
- name: dependencies
image: golang:1.11
environment:
- GO111MODULES=on
commands:
- go get -u
- name: test
image: golang:1.11
environment:
- GO111MODULES=on
- POSTGRES_USER=root
- POSTGRES_PASSWORD=
- POSTGRES_ADDR=database:26257
commands:
- go test -timeout 30s ./...
- name: build
image: golang:1.11
environment:
- GO111MODULES=on
commands:
- go build ./cmd/main.go
when:
event: [ push, tag ]
- name: docker-ci
image: plugins/docker
repo: misaki.packetlostandfound.us:5005/chiefnoah/packetlostandfoundws
pull: true
registry: misaki.packetlostandfound.us:5005
# username: ${docker_username}
# password: ${docker_password}
dockerfile: ./cmd/Dockerfile
tags:
- latest
when:
event: [deployment, push]
branches: [master, develop]
services:
- name: database
image: cockroachdb/cockroach:v2.1.0
command: [ "start", "--insecure" ]

2
cmd/main.go

@ -25,7 +25,7 @@ func main() {
}
defer db.Close()
contactService := contact.ContactService{DB: db}
contactService := contact.Service{DB: db}
contactService.Init()
r := chi.NewRouter()
contact.BindEndpoints(r, contactService)

5
go.mod

@ -2,5 +2,10 @@ module git.packetlostandfound.us/chiefnoah/packetlostandfound-ws
require (
github.com/go-chi/chi v3.3.3+incompatible
github.com/google/pprof v0.0.0-20181026152656-fde099a545de // indirect
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 // indirect
github.com/lib/pq v1.0.0
golang.org/x/arch v0.0.0-20180920145803-b19384d3c130 // indirect
golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd // indirect
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 // indirect
)

10
go.sum

@ -2,5 +2,15 @@ git.packetlostandfound.us/chiefnoah/packetlostandfound v0.0.0-20180927045543-d15
git.packetlostandfound.us/chiefnoah/packetlostandfound-ws v0.0.0-20181108050421-cc1a385feab1 h1:sqJeFfxEZDKKevtNfHhbfSYMdR4T3n6Agv1RHbtfbRE=
github.com/go-chi/chi v3.3.3+incompatible h1:KHkmBEMNkwKuK4FdQL7N2wOeB9jnIx7jR5wsuSBEFI8=
github.com/go-chi/chi v3.3.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/google/pprof v0.0.0-20181026152656-fde099a545de h1:FNVzWlo4xE8V0835Fzciova4asrBAb86Kxdyw+eXlWk=
github.com/google/pprof v0.0.0-20181026152656-fde099a545de/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 h1:UDMh68UUwekSh5iP2OMhRRZJiiBccgV7axzUG8vi56c=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
golang.org/x/arch v0.0.0-20180920145803-b19384d3c130 h1:Vsc61gop4hfHdzQNolo6Fi/sw7TnJ2yl3ZR4i7bYirs=
golang.org/x/arch v0.0.0-20180920145803-b19384d3c130/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd h1:VtIkGDhk0ph3t+THbvXHfMZ8QHgsBO39Nh52+74pq7w=
golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 h1:YoY1wS6JYVRpIfFngRf2HHo9R9dAne3xbkGOQ5rJXjU=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

14
pkg/contact/contact.go

@ -6,19 +6,27 @@ import (
"time"
)
type ContactSubmission struct {
//Submission defines the structure for a contact request
type Submission struct {
ID uint64 `json:"id"`
Email string `json:"email"`
Message string `json:"message"`
Date time.Time `json:"submission_date"`
}
type ContactService struct {
//Service defines a service for handling submitted contact forms
type Service struct {
DB *sql.DB
}
func (c *ContactService) Init() {
//Init initializes the service and creates any tables necessary in Service.DB to run the service
func (c *Service) Init() {
if _, err := c.DB.Exec("CREATE TABLE IF NOT EXISTS CONTACT_SUBMISSIONS(ID INT PRIMARY KEY, EMAIL TEXT NOT NULL, MESSAGE TEXT NOT NULL, SUBMITTED DATE NOT NULL DEFAULT CURRENT_DATE)"); err != nil {
log.Fatal(err)
}
}
//Create creates and stores a contact submission in the database
func (c *Service) Create(cs *Submission) {
panic("Not implemented")
}

3
pkg/contact/web.go

@ -7,7 +7,8 @@ import (
"github.com/go-chi/chi"
)
func BindEndpoints(r chi.Router, c ContactService) {
//BindEndpoints binds service functions to their corresponding RESTful endpoints
func BindEndpoints(r chi.Router, s Service) {
r.Post("/contact_submission", func(w http.ResponseWriter, r *http.Request) {
log.Println("Received contact submission request")
})

Loading…
Cancel
Save