Categorygithub.com/slayerjk/http-param-to-db

# README

Go: HTTP PARAM TO DB

What program does: run web server, listen for correct call and write call's param(url param('value') or json body('UUID')) to db.

This program uses Sqllite3 dbms. Required github.com/ncruces/go-sqlite3/driver.

Flags:

  • log-dir - path to logs dir; default is relative to exe - 'logs_http-param-to-db'
  • port - custom port for http server; default is 3000
  • mode - body/param; default is 'body'; read below
  • param-name - param to seek in request body/param and insert into db
  • body-condition - optional condition to be met in 'body' request, format is 'key:value'; read below
  • m - mailing ON, use 'data/mailing.json'
  • mailing-file(full path to 'mailing.json', default is in the "data/mailing.json")
  • keep-logs - number of log files to keep; default = 30; logs are rotated at start of app

'mode' flag values

'body'

* body(default) - run web server(default port is 3000) and listen for POST with application/json body. Param to take in json is by default = 'UUID'. Can be changed with flag 'param-name' and in must exist in json body. URL will be: ```https://:3000/api```

Program will try to search in root of Json, so your param must not be nested.

It's hard to predict how will json body look like, so consider your param is not nested.

Example of json body('UUID' will be found and, for example, 'delegate' will not):

{
    "UUID": "",
    "title": "",
    "type": "",
    "creationDate": {
      "delegate": "",
      "isDateTime": true
    },
    "message": {
      "lang": "",
      "text": ""
    }
  }

Normally, must be as such:

{
    "YOUR-PARAM":"***",
    "some-value":***, 
    "maybe-another-value":***
}

There is additional flag for condition to be met in json body in format "key:value". If condition is not "", then accept POST only if condition is found in reques body. This 'key-value' pair also must not be nested!

'param'

* param - run web server(default port is 3000) and listen for POST with "value" parameter in URL like ```https://:3000/api?value=```

Param to parse in request is by default = 'UUID'. Can be changed with flag 'param-name' and in must exist in callback.json.

Workflow is follow:

  1. run web server(default port is 3000) and listen for POST according to 'mode' parameter. https://<your address>:3000/api?value=<your param value>
  2. then if param is found and it's not empty it's written to the data.db

DB is simple: table 'Data' with columns: ID(INTEGER PRIMARY KEY), Value(TEXT NOT NULL UNIQUE), Posted_Date(TEXT), Processed(INTEGER(0(failed)/1(succeeded)/NULL(na))) Processed_Date(TEXT)

CREATE TABLE "Data" (
	"ID"	INTEGER,
	"Value"	TEXT NOT NULL UNIQUE,
	"Posted_Date"	TEXT,
	"Processed"	INTEGER,
	"Processed_Date"	TEXT,
	PRIMARY KEY("ID")
);

data_BLANK.db - is just empty DB with stucture described above. Rename it to data.db to use with application.

mailing

There is also in 'data' dir mailing_BLANK.json. Rename it to 'mailing.json' and fill with your values. For now only for unauthorized SMTP:25. Mail for errors and success for processed queries.

mailing.json

{
    "host": "[email protected]",
    "port": 25,
    "from_addr": "[email protected]",
    "to_addr_errors": [
        "[email protected]",
        "[email protected]"
    ],
    "to_addr_reports": [
        "[email protected]",
        "[email protected]"
    ]
}

Examples

  • Run in mode 'param': waits for POST to URL: http:///api?UUID= and writes to DB(only UNIQUE)

./http-param-to-db.exe -mode param

  • Run in mode 'param': waits for POST to URL: http:///api?my-value= and writes of 'my-value' param to DB(only UNIQUE)

./http-param-to-db.exe -mode param -param-name my-value

  • Run in mode 'body'(by default): waits for POST to URL: http:///api with not nested 'UUID' param(by default) and 'type' = 'waitingLines' (key:value) in JSON body. Writes 'UUID' value to DB(only UNIQUE)

./http-param-to-db.exe -body-condition type:waitingLines

# Packages

No description provided by the author