Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pcpratheesh/golang-influxdb-example
Sample code snippet for influxdb with golang and fiber
https://github.com/pcpratheesh/golang-influxdb-example
code example fiber go golang influx influxdb influxdb-client snippets time-series time-series-database
Last synced: about 1 month ago
JSON representation
Sample code snippet for influxdb with golang and fiber
- Host: GitHub
- URL: https://github.com/pcpratheesh/golang-influxdb-example
- Owner: pcpratheesh
- Created: 2021-08-24T06:16:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-24T06:38:13.000Z (over 3 years ago)
- Last Synced: 2024-06-20T15:49:03.414Z (7 months ago)
- Topics: code, example, fiber, go, golang, influx, influxdb, influxdb-client, snippets, time-series, time-series-database
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 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
```go
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
```go
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```yml
server:
host: server host
port: server running portinfluxInstance:
host: db host
port: db port
db: database
user: db user
password: db password
```
### Run
```go
go run main.go
```## References
- InfluxDB : https://docs.influxdata.com/influxdb/v1.8/introduction/get-started/
- InfluxDB Golang Client : https://github.com/influxdata/influxdb-client-go
- Go Fiber : https://github.com/gofiber/fiber