Skip to content
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

[WIP] 7 - Implementar HTTP DELETE/plants/{id} #21

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 0 additions & 125 deletions dao/elasticsearch.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ require (
github.com/sirupsen/logrus v1.4.2
go.elastic.co/apm/module/apmelasticsearch v1.5.0
go.elastic.co/apm/module/apmgin v1.5.0
go.elastic.co/apm/module/apmlogrus v1.5.0
go.elastic.co/apm/module/apmlogrus v1.5.0 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ github.com/elastic/go-elasticsearch/v8 v8.0.0-20190906153242-7540ece56511 h1:TM2
github.com/elastic/go-elasticsearch/v8 v8.0.0-20190906153242-7540ece56511/go.mod h1:xe9a/L2aeOgFKKgrO3ibQTnMdpAeL0GC+5/HpGScSa4=
github.com/elastic/go-sysinfo v1.0.1 h1:lzGPX2sIXaETeMXitXL2XZU8K4B7k7JBhIKWxdOdUt8=
github.com/elastic/go-sysinfo v1.0.1/go.mod h1:O/D5m1VpYLwGjCYzEt63g3Z1uO3jXfwyzzjiW90t8cY=
github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY=
github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU=
github.com/gdgtoledo/linneo v0.0.0-20190911074743-f93dba339d7d h1:CNe+fK9EpA5QYPBCRpVBmOgbeOQz2/+khM/VKm/Lbgc=
github.com/gdgtoledo/linneo v0.0.0-20190911074743-f93dba339d7d/go.mod h1:+tfKzzeB8hzCVRyg2iXTrITcFRxqrKobBYy3gB1CJdw=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=
Expand All @@ -24,8 +27,10 @@ github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwK
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
Expand All @@ -39,7 +44,9 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
Expand Down Expand Up @@ -82,10 +89,12 @@ golang.org/x/sys v0.0.0-20190425145619-16072639606e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
Expand Down
56 changes: 0 additions & 56 deletions main.go

This file was deleted.

24 changes: 24 additions & 0 deletions src/dao/dao.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dao

import (
domain "github.com/gdgtoledo/linneo/src/plants"
)

// Query to Dao search
type Query string

// ID to Dao delete
type ID string

// Response to Dao action
type Response struct {
message string
status int
response domain.Plants
}

// Interface to the data access object
type Interface interface {
Search(query Query) (Response, error)
Delete(id ID) (Response, error)
}
12 changes: 12 additions & 0 deletions src/elastic/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package elastic

import (
"github.com/gdgtoledo/linneo/src/dao"
)

// Delete by id to Elastic Dao
func (eDao DataObjectModel) Delete(id dao.ID) (dao.Response, error) {
var r dao.Response
var err error
return r, err
}
60 changes: 60 additions & 0 deletions src/elastic/elastic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package elastic

import (
"net/http"

es "github.com/elastic/go-elasticsearch/v8"
"github.com/gdgtoledo/linneo/src/dao"
log "github.com/sirupsen/logrus"
apmes "go.elastic.co/apm/module/apmelasticsearch"
)

// DataObjectModel type to elastic Dao
type DataObjectModel struct {
client *es.Client
}

var esClient *es.Client

var esClientError error

func getClient() (*es.Client, error) {
var esInstance *es.Client

if esInstance != nil {
return esInstance, nil
}

cfg := es.Config{
Addresses: []string{
"http://elasticsearch:9200",
"http://elasticsearch2:9200",
"http://elasticsearch3:9200",
},
Transport: apmes.WrapRoundTripper(http.DefaultTransport),
}

esClient, err := es.NewClient(cfg)

if err != nil {
log.WithFields(log.Fields{
"config": cfg,
"error": err,
}).Error("Could not obtain an Elasticsearch client")

return nil, err
}

esInstance = esClient

return esInstance, nil
}

func get() dao.Interface {
var edao dao.Interface

esClient, esClientError = getClient()
edao = DataObjectModel{client: esClient}

return edao
}
17 changes: 17 additions & 0 deletions src/elastic/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package elastic

import (
"github.com/gdgtoledo/linneo/src/dao"
)

// Search to Elastic Dao
func (eDao DataObjectModel) Search(query dao.Query) (dao.Response, error) {
var r dao.Response
var err error

if esClientError != nil {
return r, err
}

return r, err
}
30 changes: 30 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
dao "github.com/gdgtoledo/linneo/src/elastic"
"github.com/gdgtoledo/linneo/src/routes"
"github.com/gin-gonic/gin"
"go.elastic.co/apm/module/apmgin"
)

func handleSearch(c *gin.Context) {
r, _ := dao.Search("my query")
}

func handleDelete(c *gin.Context) {
id := c.Param("id")
r, _ := dao.Delete(id)
}

func setupRouter() *gin.Engine {
r := gin.Default()
r.Use(apmgin.Middleware(r))
r.GET(routes.Plants, handleSearch)
r.DELETE(routes.Plant, handleDelete)
return r
}

func main() {
router := setupRouter()
router.Run(":8080")
}
12 changes: 12 additions & 0 deletions src/plants/plants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package domain

type plant struct {
id string
name string
species string
genere string
geo string
}

// Plants type to a plant list
type Plants []plant
Loading