Skip to content

pcpratheesh/golang-influxdb-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang-influx-example

This is a sample respository to leanrn how we can perform influx db operations with an api endpoint.

To get all items from db

app.Get("/get", func(c *fiber.Ctx) error {
    data, err := influxInstance.GetAllItems()
    if err != nil {
        return c.Status(fiber.ErrBadGateway.Code).JSON(err.Error())
    }
    return c.JSON(data)
})

To create new entry to the db

app.Post("/create", func(c *fiber.Ctx) error {
    err := influxInstance.InsertSample()
    if err != nil {
        return c.Status(fiber.ErrBadGateway.Code).JSON(err.Error())
    }
    return c.JSON("successfully inserted")
})

configuration

  • rename config.sample.yml into config.yml
  • change the configuration variables
server:
  host: server host
  port: server running port

influxInstance:
  host: db host
  port: db port
  db: database
  user: db user
  password: db password

Run

    go run main.go

References