Code Monkey home page Code Monkey logo

device-definitions-api's Introduction

device-definitions-api

Api for managing device definitions on the DIMO platform.

For an overview of the project, see the DIMO technical documentation site.

Developing locally

TL;DR

cp settings.sample.yaml settings.yaml
docker compose up -d
go run ./cmd/device-definitions-api migrate
go run ./cmd/device-definitions-api

When working with multiple projects

Two key dependencies are postgres and redis. Problem with using docker compose is if later you need to run a different service you'll have conflicts, and most of our services as a base tend to have postgres and redis as a requirement.

So solution is just to use standalone services with brew services. https://wiki.postgresql.org/wiki/Homebrew

$ brew install postgresql $ brew services run postgresql

psql postgres create user dimo with password 'dimo'; create database device_definitions_api with owner dimo; go run ./cmd/device-definitions-api migrate

Generating client and server code

  1. Install the protocol compiler plugins for Go using the following commands
brew install protobuf
go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
  1. Run protoc in the root directory
protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    pkg/grpc/*.proto

Linting

brew install golangci-lint

golangci-lint run

This should use the settings from .golangci.yml, which you can override.

If brew version does not work, download from https://github.com/golangci/golangci-lint/releases (darwin arm64 if M1), then copy to /usr/local/bin and sudo xattr -c golangci-lint

Database ORM

This is using sqlboiler. The ORM models are code generated. If the db changes, you must update the models.

Make sure you have sqlboiler installed:

go install github.com/volatiletech/sqlboiler/v4@latest
go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest

To generate the models:

sqlboiler psql --no-tests --wipe

Make sure you're running the docker image (ie. docker compose up)

If you get a command not found error with sqlboiler, make sure your go install is correct. Instructions here

Adding migrations

To install goose in GO:

$ go get github.com/pressly/goose/v3/cmd/[email protected]
export GOOSE_DRIVER=postgres

To install goose CLI:

$ go install github.com/pressly/goose/v3/cmd/goose
export GOOSE_DRIVER=postgres

Have goose installed, then:

goose -dir internal/infrastructure/db/migrations create slugs_not_null sql

Run migration: go run ./cmd/device-definitions-api migrate

Loading Data

Importing data: Device definition exports are here You can use sqlboiler to import or this command:

psql "host=localhost port=5432 dbname=device_definitions_api user=dimo password=dimo" -c "\COPY device_definitions_api.integrations (id, type, style, vendor, created_at, updated_at, refresh_limit_secs, metadata) FROM '/Users/aenglish/Downloads/drive-download-20221020T172636Z-001/integrations.csv' DELIMITER ',' CSV HEADER"

Swagger docs

Swagger docs at: http://localhost:3000/docs/

To generate docs

go install github.com/swaggo/swag/cmd/swag@latest
swag init -g cmd/device-definitions-api/main.go --parseDependency --parseInternal --generatedTime true 
# optionally add `--parseDepth 2` if have issues

To check what cli version you have installed: swag --version.

Gotchas

If you update all libraries, it will also update a decimal library that breaks sqlboiler. You want this version: github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5 - replace it in go.mod file

Go ABI

To regenerate the Go bindings, you would run from dimo-identity repository

abigen --abi abis/DimoRegistry.json --out registry.go --pkg contracts --type Registry

device-definitions-api's People

Contributors

actions-user avatar jamesreate avatar github-actions[bot] avatar rhvivancoeffio avatar ricardovivanco avatar asfiroth avatar elffjs avatar allyson-english avatar 0xdev22 avatar dependabot[bot] avatar zavaboy avatar zer0stars avatar gurame avatar kevinjoiner avatar

Stargazers

Andy Chatham avatar

Watchers

Lucian avatar Andy Chatham avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.