Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sah4ez/tg-example
https://github.com/sah4ez/tg-example
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sah4ez/tg-example
- Owner: sah4ez
- Created: 2022-01-24T07:17:58.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-25T11:54:01.000Z (11 months ago)
- Last Synced: 2024-06-20T15:24:14.173Z (5 months ago)
- Language: Go
- Size: 9.51 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# About
Simple example usage tg.
# Update transport
```bash
go generate ./...
```# Run servcie
```bash
go run ./cmd/example/main.go
```# API Example
Request:
```bash
curl -X POST "http://localhost:9000/" -H "Content-Type: application/json" -d '[{"id":"123", "jsonrpc":"2.0", "method":"user.getUserNameByID", "params":{"id":1}}]'
```Response for error:
```bash
[{"id":"123","jsonrpc":"2.0","error":{"code":-32603,"message":"user not found: record not found","data":{}}}]
```Prepare user data:
```bash
psql 'host=localhost port=5432 user=postgres dbname=postgres password=secretpass sslmode=disable client_encoding=UTF8' -c "insert into users(name) values('user2');"# INSERT 0 1
```Response with username:
```bash
[{"id":"123","jsonrpc":"2.0","result":{"name":"user"}}]
```Log on server:
```
./bin/example
2022-03-25T00:52:57+03:00 ??? hello world
2022-03-25T00:52:58+03:00 INF listen on bind=:90002022/03/25 00:53:02 /home/sah4ez/go/src/github.com/sah4ez/tg-example/pkg/storage/user.go:11 record not found
[2.101ms] [rows:0] SELECT * FROM "users" WHERE id = 1 ORDER BY "users"."id" LIMIT 1
2022-03-25T00:53:02+03:00 ERR call getUserNameByID error="user not found: record not found" method=getUserNameByID request={Id:1} response={Name:} service=User took=2.545998ms
2022-03-25T00:54:36+03:00 INF call getUserNameByID method=getUserNameByID request={Id:1} response={Name:user} service=User took=2.123242ms
```# Serve binary data
Prepare embeded files:
```
cd pkg/files/
rice embed-go
```