Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Chakib Benziane | 57b7fd0889 | 5 years ago |
Chakib Benziane | 6adad435fa | 5 years ago |
Chakib Benziane | 60ea287ccd | 5 years ago |
Chakib Benziane | 16da18eda3 | 5 years ago |
Chakib Benziane | f880881b9b | 5 years ago |
Chakib Benziane | 0145558cc8 | 5 years ago |
Chakib Benziane | 9b18f725d1 | 5 years ago |
Chakib Benziane | 8dce666783 | 5 years ago |
@ -1,11 +0,0 @@
|
|||||||
FROM golang:alpine
|
|
||||||
|
|
||||||
RUN mkdir -p /src
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
ENV GO111MODULE=on
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
RUN go build
|
|
||||||
|
|
||||||
CMD ["bit4sat"]
|
|
@ -1 +1 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/home/spike/projects/bit4sat/server/db-storage/bit4sat.sqlite" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser query pragmas" current="1"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="2105"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="upload"/><default_encoding codec=""/><browse_table_settings><table schema="" name="" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths/><filter_values/><conditional_formats/><display_formats/><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths><column index="1" value="275"/><column index="2" value="176"/><column index="3" value="256"/></column_widths><filter_values/><conditional_formats/><display_formats><column index="7" value=""/></display_formats><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload_status" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths/><filter_values/><conditional_formats/><display_formats/><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload_with_status" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths><column index="7" value="0"/><column index="8" value="0"/></column_widths><filter_values/><conditional_formats/><display_formats/><hidden_columns><column index="7" value="1"/><column index="8" value="1"/></hidden_columns><plot_y_axes/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 1">SELECT EXISTS (SELECT upload_id FROM upload WHERE upload_id = '1Ijbco3pYIrl2VzTslERxszEHG1');</sql><sql name="SQL 2">SELECT * FROM upload JOIN upload_status ON upload.status = upload_status.type;</sql><current_tab id="1"/></tab_sql></sqlb_project>
|
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/home/spike/projects/bit4sat/db-storage/bit4sat.sqlite" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser query pragmas" current="1"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="2105"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="upload"/><default_encoding codec=""/><browse_table_settings><table schema="" name="" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths/><filter_values/><conditional_formats/><display_formats/><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths><column index="1" value="275"/><column index="2" value="176"/><column index="3" value="256"/></column_widths><filter_values/><conditional_formats/><display_formats><column index="7" value=""/></display_formats><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload_status" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths/><filter_values/><conditional_formats/><display_formats/><hidden_columns/><plot_y_axes/></table><table schema="main" name="upload_with_status" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk=""><sort/><column_widths><column index="7" value="0"/><column index="8" value="0"/></column_widths><filter_values/><conditional_formats/><display_formats/><hidden_columns><column index="7" value="1"/><column index="8" value="1"/></hidden_columns><plot_y_axes/></table></browse_table_settings></tab_browse><tab_sql><sql name="SQL 1">SELECT EXISTS (SELECT upload_id FROM upload WHERE upload_id = '1Ijbco3pYIrl2VzTslERxszEHG1');</sql><sql name="SQL 2">SELECT * FROM upload JOIN upload_status ON upload.status = upload_status.type;</sql><current_tab id="1"/></tab_sql></sqlb_project>
|
||||||
|
@ -1,28 +1,70 @@
|
|||||||
version: "3.4"
|
version: "3.4"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
redis:
|
db:
|
||||||
name: bit4sat-data
|
maria-conf:
|
||||||
|
postgresql:
|
||||||
|
file-storage:
|
||||||
|
#sqlite:
|
||||||
|
gocache:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
bit4sat:
|
app:
|
||||||
image: sp4ke/bit4sat
|
image: sp4ke/bit4sat
|
||||||
build:
|
build: ./docker
|
||||||
context: .
|
|
||||||
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
- GO111MODULE=on
|
- GO111MODULE=on
|
||||||
|
- BIT4SAT_STORAGE_PATH=/storage
|
||||||
|
- GOPATH=/go
|
||||||
|
- DB_HOST=maria
|
||||||
|
- DB_USER=bit4sat
|
||||||
|
- DB_PASS=bit4sat
|
||||||
|
- LN_CHARGE_API=10.192.122.10:9112
|
||||||
|
- LN_CHARGE_TOKEN=3emU3Fy8VasHCzMaMXHSVJYpQSqH3yXQj8N5cQFBbq3botrudJuR7zQkBBmFSbAmgXs9GD4j4U3J4R2sMfgqPo8q
|
||||||
|
|
||||||
deploy:
|
#deploy:
|
||||||
replicas: 1
|
#replicas: 1
|
||||||
|
#
|
||||||
|
ports:
|
||||||
|
- "8880:8880"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD:/src
|
- $PWD:/src
|
||||||
|
- gocache:/go
|
||||||
|
#- ./db-storage:/sqlite
|
||||||
|
- file-storage:/storage
|
||||||
|
|
||||||
working_dir: /src
|
working_dir: /src
|
||||||
|
|
||||||
command:
|
maria:
|
||||||
- go
|
image: mariadb:latest
|
||||||
- "run *.go"
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=pass
|
||||||
|
- MYSQL_DATABASE=bit4sat
|
||||||
|
- MYSQL_USER=bit4sat
|
||||||
|
- MYSQL_PASSWORD=bit4sat
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- db:/var/lib/mysql
|
||||||
|
- maria-conf:/etc/mysql
|
||||||
|
postgres:
|
||||||
|
image: postgres:11.2
|
||||||
|
environment:
|
||||||
|
- POSTGRES_PASSWORD=bit4sat
|
||||||
|
- POSTGRES_USER=bit4sat
|
||||||
|
- POSTGRES_DB=bit4sat
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- postgresql:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:alpine
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- db:/data
|
||||||
|
|
||||||
|
command:
|
||||||
|
- redis-server
|
||||||
|
- --appendonly yes
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
FROM golang:alpine
|
||||||
|
|
||||||
|
RUN apk update && apk add --no-cache \
|
||||||
|
git \
|
||||||
|
bash \
|
||||||
|
gcc build-base make
|
||||||
|
|
||||||
|
RUN mkdir -p /src
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
ENV GO111MODULE=on
|
||||||
|
ADD entrypoint.sh /entry
|
||||||
|
RUN chmod +x /entry
|
||||||
|
|
||||||
|
CMD ["/entry"]
|
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
go build -v
|
||||||
|
exec ./bit4sat
|
@ -0,0 +1,124 @@
|
|||||||
|
package ln
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CurMSat = iota
|
||||||
|
CurSat
|
||||||
|
CurUSD
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LNChargeAPIEnv = "LN_CHARGE_API"
|
||||||
|
LNChargeTokenEnv = "LN_CHARGE_TOKEN"
|
||||||
|
InfoEndpoint = "info"
|
||||||
|
InvoiceEndpoint = "invoice"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
LNCEndpoint string
|
||||||
|
LNChargeToken string
|
||||||
|
)
|
||||||
|
|
||||||
|
type Charge struct {
|
||||||
|
client *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCharge() *Charge {
|
||||||
|
netTransport := &http.Transport{
|
||||||
|
Dial: (&net.Dialer{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}).Dial,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
c := &http.Client{
|
||||||
|
Timeout: time.Second * 10,
|
||||||
|
Transport: netTransport,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Charge{
|
||||||
|
client: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Charge) Info() (gin.H, error) {
|
||||||
|
|
||||||
|
result := make(gin.H)
|
||||||
|
resp, err := c.client.Get(getUrl(InfoEndpoint))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonDec := json.NewDecoder(resp.Body)
|
||||||
|
jsonDec.Decode(&result)
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Charge) Invoice(amount int, id string) (gin.H, error) {
|
||||||
|
|
||||||
|
result := make(gin.H)
|
||||||
|
reqData := gin.H{
|
||||||
|
"amount": 10,
|
||||||
|
"currency": "USD",
|
||||||
|
"description": fmt.Sprintf("bit4sat upload: %s", id),
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonEnc, err := json.Marshal(reqData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.client.Post(getUrl(InvoiceEndpoint),
|
||||||
|
"application/json",
|
||||||
|
bytes.NewReader(jsonEnc))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result = make(gin.H)
|
||||||
|
jsonDec := json.NewDecoder(resp.Body)
|
||||||
|
jsonDec.Decode(&result)
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUrl(endpoint string) string {
|
||||||
|
url, err := url.Parse(fmt.Sprintf("http://api-token:%s@%s/%s",
|
||||||
|
LNChargeToken,
|
||||||
|
LNCEndpoint,
|
||||||
|
endpoint))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.String()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var set bool
|
||||||
|
LNCEndpoint, set = os.LookupEnv(LNChargeAPIEnv)
|
||||||
|
if !set {
|
||||||
|
log.Fatalf("%s not set", LNChargeAPIEnv)
|
||||||
|
}
|
||||||
|
|
||||||
|
LNChargeToken, set = os.LookupEnv(LNChargeTokenEnv)
|
||||||
|
if !set {
|
||||||
|
log.Fatalf("%s not set", LNChargeAPIEnv)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue