Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ config.json
*.csr
*.sublime-project
*.sublime-workspace

### Docs ###
doc/
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ Copy config.json.sample to config.json and edit to match your information.

`go build core/server.go`

## Docs

Api docs are available at https://openaccounting.io/api/

You may also build and run the docs locally with [apidoc](apidocjs.com)

#### Requires [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/)

### Step 1:

Install `apidoc`

```bash
npm install apidoc -g
```

### Step 2:

Simply run `apidoc` within the source code root directory, this will automatically generate the documentation and write the output to`./doc`

```bash
apidoc
```

### Step 3:

You may now navigate to the `./docs` directory and run any http server, or simply open `index.html` in your favorite browser!

## Help

[Join our Slack chatroom](https://join.slack.com/t/openaccounting/shared_invite/enQtNDc3NTAyNjYyOTYzLTc0ZjRjMzlhOTg5MmYwNGQxZGQyM2IzZTExZWE0NDFlODRlNGVhZmZiNDkyZDlhODYwZDcyNTQ5ZWJkMDU3N2M) and talk with us!
[Join our Slack chatroom](https://join.slack.com/t/openaccounting/shared_invite/enQtNDc3NTAyNjYyOTYzLTc0ZjRjMzlhOTg5MmYwNGQxZGQyM2IzZTExZWE0NDFlODRlNGVhZmZiNDkyZDlhODYwZDcyNTQ5ZWJkMDU3N2M) and talk with us!
17 changes: 17 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"WebUrl": "https://domain.com",
"Address": "",
"Port": 8080,
"ApiPrefix": "",
"KeyFile": "",
"CertFile": "",
"DatabaseAddress": "localhost:5432",
"Database": "openaccounting?sslmode=disable",
"User": "postgresql://openaccounting",
"Password": "openaccounting",
"MailgunDomain": "mg.domain.com",
"MailgunKey": "",
"MailgunEmail": "noreply@domain.com",
"MailgunSender": "Sender",
"Driver": "postgres"
}
5 changes: 3 additions & 2 deletions core/model/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)

type DB struct {
Expand All @@ -22,9 +23,9 @@ type Datastore interface {
BudgetInterface
}

func NewDB(dataSourceName string) (*DB, error) {
func NewDB(dataSourceName string, sqldialict string) (*DB, error) {
var err error
db, err := sql.Open("mysql", dataSourceName)
db, err := sql.Open(sqldialict, dataSourceName)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions core/model/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type Config struct {
MailgunKey string
MailgunEmail string
MailgunSender string
Driver string
}
16 changes: 15 additions & 1 deletion core/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ func main() {
log.Fatal(fmt.Errorf("failed to open ./config.json with: %s", err.Error()))
}


decoder := json.NewDecoder(file)
err = decoder.Decode(&config)

if err != nil {
log.Fatal(fmt.Errorf("failed to decode ./config.json with: %s", err.Error()))
} else {
log.Println("Config success")
}

connectionString := config.User + ":" + config.Password + "@" + config.DatabaseAddress + "/" + config.Database

db, err := db.NewDB(connectionString)
db, err := db.NewDB(connectionString, config.Driver)
if err != nil {
log.Fatal(fmt.Errorf("failed to connect to database with: %s", err.Error()))
} else {
log.Println("DB connection successfull")
}

bc := &util.StandardBcrypt{}
Expand All @@ -47,11 +52,20 @@ func main() {
app, err := api.Init(config.ApiPrefix)
if err != nil {
log.Fatal(fmt.Errorf("failed to create api instance with: %s", err.Error()))
} else {
log.Println("API config successfull")
}

if config.CertFile == "" || config.KeyFile == "" {
err = http.ListenAndServe(config.Address+":"+strconv.Itoa(config.Port), app.MakeHandler())
log.Println("CertFile is null",err)
if err != nil {
log.Fatal(fmt.Errorf("failed to start server : %s", err.Error()))
} else {
log.Println("Server runnging successfull on ", config.Port)
}
} else {
log.Println("CertFile is not null")
err = http.ListenAndServeTLS(config.Address+":"+strconv.Itoa(config.Port), config.CertFile, config.KeyFile, app.MakeHandler())
}
log.Fatal(fmt.Errorf("failed to start server with: %s", err.Error()))
Expand Down
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
module github.com/openaccounting/oa-server

go 1.17

require (
github.com/Masterminds/semver v0.0.0-20180807142431-c84ddcca87bf
github.com/ant0ine/go-json-rest v0.0.0-20170913041208-ebb33769ae01
github.com/go-sql-driver/mysql v1.4.1
github.com/gorilla/websocket v0.0.0-20180605202552-5ed622c449da
github.com/lib/pq v1.10.3
github.com/mailgun/mailgun-go/v4 v4.3.0
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675
github.com/sendgrid/rest v0.0.0-20180905234047-875828e14d98 // indirect
github.com/sendgrid/sendgrid-go v0.0.0-20180905233524-8cb43f4ca4f5 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
google.golang.org/appengine v1.6.7 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-chi/chi v4.0.0+incompatible // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ github.com/go-chi/chi v4.0.0+incompatible h1:SiLLEDyAkqNnw+T/uDTf3aFB9T4FTrwMpuY
github.com/go-chi/chi v4.0.0+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v0.0.0-20180605202552-5ed622c449da h1:b5fma7aUP2fn6+tdKKCJ0TxXYzY/5wDiqUxNdyi5VF4=
github.com/gorilla/websocket v0.0.0-20180605202552-5ed622c449da/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mailgun/mailgun-go/v4 v4.3.0 h1:9nAF7LI3k6bfDPbMZQMMl63Q8/vs+dr1FUN8eR1XMhk=
github.com/mailgun/mailgun-go/v4 v4.3.0/go.mod h1:fWuBI2iaS/pSSyo6+EBpHjatQO3lV8onwqcRy7joSJI=
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 h1:/rdJjIiKG5rRdwG5yxHmSE/7ZREjpyC0kL7GxGT/qJw=
Expand All @@ -34,30 +35,17 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/sendgrid/rest v0.0.0-20180905234047-875828e14d98 h1:wpBZ5DAYLNl+2v4E4WP8k/y8tM5OjIf1FezJS1qX8sU=
github.com/sendgrid/rest v0.0.0-20180905234047-875828e14d98/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/sendgrid/sendgrid-go v0.0.0-20180905233524-8cb43f4ca4f5 h1:V18LU+jSbihmDiWfLSzs9FV1d3KVB1gRTkNxgVHmcvg=
github.com/sendgrid/sendgrid-go v0.0.0-20180905233524-8cb43f4ca4f5/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d h1:GrqEEc3+MtHKTsZrdIGVoYDgLpbSRzW1EF+nLu0PcHE=
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
2 changes: 1 addition & 1 deletion migrations/migrate1.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
}

connectionString := config.User + ":" + config.Password + "@/" + config.Database
db, err := db.NewDB(connectionString)
db, err := db.NewDB(connectionString, "mysql")

if command == "upgrade" {
err = upgrade(db)
Expand Down
2 changes: 1 addition & 1 deletion migrations/migrate2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
}

connectionString := config.User + ":" + config.Password + "@/" + config.Database
db, err := db.NewDB(connectionString)
db, err := db.NewDB(connectionString, "mysql")

if command == "upgrade" {
err = upgrade(db)
Expand Down
2 changes: 1 addition & 1 deletion migrations/migrate3.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
}

connectionString := config.User + ":" + config.Password + "@/" + config.Database
db, err := db.NewDB(connectionString)
db, err := db.NewDB(connectionString, "mysql")

if command == "upgrade" {
err = upgrade(db)
Expand Down
37 changes: 37 additions & 0 deletions schema_postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DROP DATABASE IF EXISTS openaccounting;

CREATE DATABASE openaccounting
WITH
OWNER = openaccounting
ENCODING = 'UTF8'
CONNECTION LIMIT = -1;

use openaccounting;

CREATE TABLE org (id CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, name VARCHAR(100) NOT NULL, currency VARCHAR(10) NOT NULL, precision INT NOT NULL, timezone VARCHAR(100) NOT NULL);

CREATE TABLE "user" (id CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, firstName VARCHAR(50) NOT NULL, lastName VARCHAR(50) NOT NULL, email VARCHAR(100) NOT NULL, passwordHash VARCHAR(100) NOT NULL, agreeToTerms BOOLEAN NOT NULL, passwordReset VARCHAR(32) NOT NULL, emailVerified BOOLEAN NOT NULL, emailVerifyCode VARCHAR(32) NOT NULL, signupSource VARCHAR(100) NOT NULL, UNIQUE(email));

CREATE TABLE userorg (id SERIAL PRIMARY KEY, userId CHAR(16) NOT NULL, orgId CHAR(16) NOT NULL, admin BOOLEAN NOT NULL DEFAULT false);

CREATE TABLE token (id CHAR(16) NOT NULL, name VARCHAR(100), userOrgId INT NOT NULL);

CREATE TABLE account (id CHAR(16) NOT NULL, orgId CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, name VARCHAR(100) NOT NULL, parent CHAR(16) NOT NULL, currency VARCHAR(10) NOT NULL, precision INT NOT NULL, debitBalance BOOLEAN NOT NULL);

CREATE TABLE transaction (id CHAR(16) NOT NULL, orgId CHAR(16) NOT NULL, userId CHAR(16) NOT NULL, date BIGINT NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, description VARCHAR(300) NOT NULL, data TEXT NOT NULL, deleted BOOLEAN NOT NULL DEFAULT false);

CREATE TABLE split (id SERIAL PRIMARY KEY, transactionId CHAR(16) NOT NULL, accountId CHAR(16) NOT NULL, date BIGINT NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, amount BIGINT NOT NULL, nativeAmount BIGINT NOT NULL, deleted BOOLEAN NOT NULL DEFAULT false);

CREATE TABLE balance (id SERIAL PRIMARY KEY, date BIGINT NOT NULL, accountId CHAR(16) NOT NULL, amount BIGINT NOT NULL);

CREATE TABLE permission (id CHAR(16) NOT NULL, userId CHAR(16), tokenId CHAR(16), orgId CHAR(16) NOT NULL, accountId CHAR(16) NOT NULL, type INT NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL);

CREATE TABLE price (id CHAR(16) NOT NULL, orgId CHAR(16) NOT NULL, currency VARCHAR(10) NOT NULL, date BIGINT NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, price DOUBLE PRECISION NOT NULL);

CREATE TABLE session (id CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, userId CHAR(16) NOT NULL, terminated BIGINT );

CREATE TABLE apikey (id CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, userId CHAR(16) NOT NULL, label VARCHAR(300) NOT NULL, deleted BIGINT );

CREATE TABLE invite (id VARCHAR(32) NOT NULL, orgId CHAR(16) NOT NULL, inserted BIGINT NOT NULL, updated BIGINT NOT NULL, email VARCHAR(100) NOT NULL, accepted BOOLEAN NOT NULL);

CREATE TABLE budgetitem (id SERIAL PRIMARY KEY, orgId CHAR(16) NOT NULL, accountId CHAR(16) NOT NULL, inserted BIGINT NOT NULL, amount BIGINT NOT NULL);
11 changes: 0 additions & 11 deletions vendor/github.com/json-iterator/go/go.mod

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/json-iterator/go/go.sum

This file was deleted.

12 changes: 0 additions & 12 deletions vendor/github.com/mailgun/mailgun-go/v4/go.mod

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/mailgun/mailgun-go/v4/go.sum

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/stretchr/objx/go.mod

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/stretchr/objx/go.sum

This file was deleted.

Loading