1
0
This commit is contained in:
Your Name 2024-02-21 09:16:45 +00:00 committed by syui
parent f7df1224e0
commit 8c6be8273e
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
74 changed files with 318 additions and 217 deletions

View File

@ -1 +1 @@
web: bin/t
web: bin/api

View File

@ -6,7 +6,18 @@ su=5000
go generate ./...
cp -rf $d/ent/openapi.json $d/tmp/
case $OSTYPE in
darwin*)
sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
sed -i '' "s/255/$su/g" $d/ent/openapi.json
;;
linux*)
sed -i "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
sed -i "s/255/$su/g" $d/ent/openapi.json
;;
esac
cp -rf $d/tmp/ogent ent/
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go build
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go run -mod=mod main.go

133
docs/wiki.md Normal file
View File

@ -0,0 +1,133 @@
### build
```sh
$ vim ent/entc.go
$ vim ent/schema/users.go
$ go generate ./...
$ go build
$ ./card
$ go generate ./...
$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards
$ curl localhost:8080/users
$ curl localhost:8080/cards
$ curl localhost:8080/users/1
$ curl localhost:8080/users/1/card
```
### use
```sh
$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users
# onconflict
$ !!
$ curl -sL https://api.syui.ai/users/1
```
```sh
# item select
$ curl -sL "https://api.syui.ai/users?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255"
```
### ref
```sh
$ vim ./ent/ogent/ogent.go
// 新規登録の停止
// CreateUsers handles POST /users-slice requests.
func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) {
b := h.client.Users.Create()
//b.SetUser(req.User)
b.SetUser("syui")
}
// 削除の無効
// DeleteUsers handles DELETE /users-slice/{id} requests.
func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) {
if params.ID != 1 {
err := h.client.Users.DeleteOneID(params.ID).Exec(ctx)
}
return new(DeleteUsersNoContent), nil
}
// 要素の書き換えの禁止
// UpdateUsers handles PATCH /users-slice/{id} requests.
func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) {
b := h.client.Users.UpdateOneID(params.ID)
// Add all fields.
//if v, ok := req.Hp.Get(); ok {
// b.SetHp(v)
//}
```
### link
- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/
- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go
- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go
- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent
### update
```sh
$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less
```
> ent/ogent/oas_response_encoders_gen.go
```go
func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
switch response := response.(type) {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
```
### northflank
#### backup sqlite
- `cron`, `repo(private)`, `pass(token)`
```sh
#!/bin/zsh
pass=password
/usr/bin/northflank exec service --project $project --service $service --cmd "/app/data/api/backup.sh $pass"
function f(){
rm /app/data/api/backup.sh
echo '#!/bin/bash
pass=$1
git config --global user.email syui@syui.ai
git config --global user.name syui
cp -rf /app/data/new.sqlite /app/data/api/latest.sqlite
cp -rf /app/data/new.sqlite /app/data/api/`date '+%w'`.sqlite
cd /app/data/api
git remote add origin https://$pass@github.com/ai/api
git add .
git commit -m backup
git push origin main
git remote rm origin
' >> /app/data/api/backup.sh
chmod +x /app/data/api/backup.sh
}
```
#### setting
- ports : http, 8080, dns=api.syui.ai
- env : PASS=xxx, TOKEN=xxx
- cmd-override : /bin/api
- volumes : /app/data

View File

@ -3,10 +3,10 @@
package ent
import (
"api/ent/card"
"api/ent/user"
"fmt"
"strings"
"t/ent/card"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package card
import (
"t/ent/predicate"
"api/ent/predicate"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,11 +3,11 @@
package ent
import (
"api/ent/card"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"context"
"t/ent/card"
"t/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context"
"fmt"
"math"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -8,12 +8,12 @@ import (
"fmt"
"log"
"t/ent/migrate"
"api/ent/migrate"
"t/ent/card"
"t/ent/group"
"t/ent/ue"
"t/ent/user"
"api/ent/card"
"api/ent/group"
"api/ent/ue"
"api/ent/user"
"entgo.io/ent"
"entgo.io/ent/dialect"

View File

@ -3,14 +3,14 @@
package ent
import (
"api/ent/card"
"api/ent/group"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"reflect"
"t/ent/card"
"t/ent/group"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"

View File

@ -3,12 +3,12 @@
package enttest
import (
"api/ent"
"context"
"t/ent"
// required by schema hooks.
_ "t/ent/runtime"
_ "api/ent/runtime"
"t/ent/migrate"
"api/ent/migrate"
"entgo.io/ent/dialect/sql/schema"
)

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/group"
"fmt"
"strings"
"t/ent/group"
"entgo.io/ent/dialect/sql"
)

View File

@ -3,7 +3,7 @@
package group
import (
"t/ent/predicate"
"api/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,11 +3,11 @@
package ent
import (
"api/ent/group"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/group"
"t/ent/user"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"context"
"t/ent/group"
"t/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,13 +3,13 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context"
"database/sql/driver"
"fmt"
"math"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package hook
import (
"api/ent"
"context"
"fmt"
"t/ent"
)
// The CardFunc type is an adapter to allow the use of ordinary

View File

@ -129,7 +129,7 @@ var (
{Name: "ten_post", Type: field.TypeString, Nullable: true},
{Name: "ten_get", Type: field.TypeString, Nullable: true},
{Name: "ten_at", Type: field.TypeTime, Nullable: true},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20240213"},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20240220"},
{Name: "room", Type: field.TypeInt, Nullable: true},
{Name: "model", Type: field.TypeBool, Nullable: true},
{Name: "model_at", Type: field.TypeTime, Nullable: true},

View File

@ -3,15 +3,15 @@
package ent
import (
"api/ent/card"
"api/ent/group"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"sync"
"t/ent/card"
"t/ent/group"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"time"
"entgo.io/ent"

View File

@ -6,11 +6,11 @@ import (
"context"
"net/http"
"t/ent"
"t/ent/card"
"t/ent/group"
"t/ent/ue"
"t/ent/user"
"api/ent"
"api/ent/card"
"api/ent/group"
"api/ent/ue"
"api/ent/user"
"os"
"github.com/go-faster/jx"
)

View File

@ -2,7 +2,7 @@
package ogent
import "t/ent"
import "api/ent"
func NewCardCreate(e *ent.Card) *CardCreate {
if e == nil {

View File

@ -3,11 +3,11 @@
package ent
import (
"t/ent/card"
"t/ent/group"
"t/ent/schema"
"t/ent/ue"
"t/ent/user"
"api/ent/card"
"api/ent/group"
"api/ent/schema"
"api/ent/ue"
"api/ent/user"
"time"
)

View File

@ -2,7 +2,7 @@
package runtime
// The schema-stitching logic is generated in t/ent/runtime.go
// The schema-stitching logic is generated in api/ent/runtime.go
const (
Version = "v0.11.10" // Version of ent codegen.

View File

@ -3,10 +3,10 @@
package ent
import (
"api/ent/ue"
"api/ent/user"
"fmt"
"strings"
"t/ent/ue"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package ue
import (
"t/ent/predicate"
"api/ent/predicate"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,11 +3,11 @@
package ent
import (
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/ue"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/predicate"
"api/ent/ue"
"context"
"t/ent/predicate"
"t/ent/ue"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context"
"fmt"
"math"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/user"
"fmt"
"strings"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package user
import (
"t/ent/predicate"
"api/ent/predicate"
"time"
"entgo.io/ent/dialect/sql"

View File

@ -3,12 +3,12 @@
package ent
import (
"api/ent/card"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/ue"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent
import (
"api/ent/predicate"
"api/ent/user"
"context"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,14 +3,14 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context"
"database/sql/driver"
"fmt"
"math"
"t/ent/card"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,13 +3,13 @@
package ent
import (
"api/ent/card"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context"
"errors"
"fmt"
"t/ent/card"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"time"
"entgo.io/ent/dialect/sql"

4
go.mod
View File

@ -1,6 +1,6 @@
module t
module api
go 1.19
go 1.21
//replace ariga.io/ogent => ../../

31
go.sum
View File

@ -1,26 +1,17 @@
ariga.io/atlas v0.9.1 h1:EpoPMnwsQG0vn9c0sYExpwSYtr7bvuSUXzQclU2pMjc=
ariga.io/atlas v0.9.1/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU=
ariga.io/atlas v0.9.2-0.20230303073438-03a4779a6338 h1:8kmSV3mbQKn0niZ/EdE11uhFvFKiW1VlaqVBIYOyahM=
ariga.io/atlas v0.9.2-0.20230303073438-03a4779a6338/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU=
ariga.io/entviz v0.0.0-20230125130633-6c9be8e08c7c h1:7FbOjKKWKqD7FZXQq3qWcRlvGFO1LGYvVZIWQ2D9Evs=
ariga.io/entviz v0.0.0-20230125130633-6c9be8e08c7c/go.mod h1:wArXZPqbbWBcOmkqwmIF6hIcW+3T1NLDde0iRhW6an8=
ariga.io/ogent v0.0.0-20230309073626-8dc564a6a73e h1:8mxC+4Y7pVKgfoUJIMdChrS95d+TcJ6xuhw49nVYIAY=
ariga.io/ogent v0.0.0-20230309073626-8dc564a6a73e/go.mod h1:95vCbvAYAW6NsWUrSL23k2SQykuf/yjellmwV1X+svI=
entgo.io/contrib v0.3.5 h1:wY85TgRp3j5ix/SZ9IE6Ob5lObHFmVUYH0ZFw1D5Hzc=
entgo.io/contrib v0.3.5/go.mod h1:R5HiFszVD8OVOZKFGRbqYogRxK7z1ruzWyEEesjQwE0=
entgo.io/ent v0.11.9 h1:dbbCkAiPVTRBIJwoZctiSYjB7zxQIBOzVSU5H9VYIQI=
entgo.io/ent v0.11.9/go.mod h1:KWHOcDZn1xk3mz3ipWdKrQpMvwqa/9B69TUuAPP9W6g=
entgo.io/ent v0.11.10 h1:iqn32ybY5HRW3xSAyMNdNKpZhKgMf1Zunsej9yPKUI8=
entgo.io/ent v0.11.10/go.mod h1:mzTZ0trE+jCQw/fnzijbm5Mck/l8Gbg7gC/+L1COyzM=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/Khan/genqlient v0.5.0 h1:TMZJ+tl/BpbmGyIBiXzKzUftDhw4ZWxQZ+1ydn0gyII=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.8.0 h1:rJD5HeGIT/2b5CDk63FVCwZA3qgYElfg+oQK7uH5pfE=
github.com/dlclark/regexp2 v1.8.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
@ -41,10 +32,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@ -52,48 +40,32 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl/v2 v2.15.0 h1:CPDXO6+uORPjKflkWCCwoWc9uRp+zSIPcCQ+BrxV7m8=
github.com/hashicorp/hcl/v2 v2.15.0/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kyokomi/lottery v1.2.0 h1:oW9YxYv5j/nu/Kkf8K5tu7Vn8dAoZTjluDxihTPX/68=
github.com/kyokomi/lottery v1.2.0/go.mod h1:TkKpJrFrOJNHpblUqYu0bAQWil3NMwKMBluHyqFfU6Y=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mazen160/go-random v0.0.0-20210308102632-d2b501c85c03 h1:iM7JTVzKOYKWjzhGcgHAgFVQt5QfiHIVrRUaWPfh0Q4=
github.com/mazen160/go-random v0.0.0-20210308102632-d2b501c85c03/go.mod h1:APoDd0B2pYeB5kU/g7Mw14mFsljp5HfzrC7arsKbi8U=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/ogen-go/ogen v0.59.0 h1:9aSSZ1KCLJIcRyjkO7IHrG0vAI6l1BO877LwTbMcX+k=
github.com/ogen-go/ogen v0.59.0/go.mod h1:0MHLcWEbxwdvR+R9E05paQSRh/2vHtVSJgKqmwYyW8M=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
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/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/vektah/gqlparser/v2 v2.4.5 h1:C02NsyEsL4TXJB7ndonqTfuQOL4XPIu0aAWugdmTgmc=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
@ -105,7 +77,6 @@ go.opentelemetry.io/otel/trace v1.13.0 h1:CBgRZ6ntv+Amuj1jDsMhZtlAPT6gbyIRdaIzFh
go.opentelemetry.io/otel/trace v1.13.0/go.mod h1:muCvmmO9KKpvuXSf3KKAXXB2ygNYHQ+ZfI5X08d3tds=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
@ -148,10 +119,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

BIN
icon/card.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

View File

@ -5,8 +5,8 @@ import (
"log"
"net/http"
"t/ent"
"t/ent/ogent"
"api/ent"
"api/ent/ogent"
"entgo.io/ent/dialect"
_ "github.com/mattn/go-sqlite3"
"entgo.io/ent/dialect/sql/schema"

View File

@ -1,94 +1,15 @@
### build
## ai `api`
<img src="./icon/card.png" width="100">
- name : ai `api`
- host : [card.syui.ai](https://card.syui.ai)
```sh
$ vim ent/entc.go
$ vim ent/schema/users.go
$ go generate ./...
$ go build
$ ./card
$ go generate ./...
$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards
$ curl localhost:8080/users
$ curl localhost:8080/cards
$ curl localhost:8080/users/1
$ curl localhost:8080/users/1/card
```
### use
```sh
$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users
# onconflict
$ !!
$ curl -sL https://api.syui.ai/users/1
```
```sh
# item select
$ curl -sL "https://api.syui.ai/users?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255"
$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255"
```
## link
### ref
- https://github.com/ariga/ogent
```sh
$ vim ./ent/ogent/ogent.go
// 新規登録の停止
// CreateUsers handles POST /users-slice requests.
func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) {
b := h.client.Users.Create()
//b.SetUser(req.User)
b.SetUser("syui")
}
// 削除の無効
// DeleteUsers handles DELETE /users-slice/{id} requests.
func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) {
if params.ID != 1 {
err := h.client.Users.DeleteOneID(params.ID).Exec(ctx)
}
return new(DeleteUsersNoContent), nil
}
// 要素の書き換えの禁止
// UpdateUsers handles PATCH /users-slice/{id} requests.
func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) {
b := h.client.Users.UpdateOneID(params.ID)
// Add all fields.
//if v, ok := req.Hp.Get(); ok {
// b.SetHp(v)
//}
```
### link
- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/
- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go
- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go
- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent
### update
```sh
$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less
```
> ent/ogent/oas_response_encoders_gen.go
```go
func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
switch response := response.(type) {
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
```

View File

@ -1,3 +0,0 @@
#!/bin/zsh
d=${0:a:h}
PASS=`cat token.json|jq -r .password` go run -mod=mod main.go

23
scpt/card_day.zsh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/zsh
case $OSTYPE in
darwin*)
alias date="/opt/homebrew/bin/gdate"
;;
esac
host=https://api.syui.ai
token=`cat ~/.config/atr/api_card.json|jq -r .token`
host_users="$host/users?itemsPerPage=2550"
data=`curl -sL "$host_users"|jq .`
nd=`date +"%Y%m%d"`
n=`echo $data|jq length`
n=$((n - 1))
for ((i=0;i<=$n;i++))
do
name=`echo $data|jq ".[$i]"|jq -r .username`
id=`echo $data|jq ".[$i]"|jq -r .id`
echo "{\"next\":\"$nd\"} -s $host/users/$id"
curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\",\"token\":\"$token\"}" -s $host/users/$id
done

23
scpt/card_delete.zsh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/zsh
if [ -z "$1" ];then
exit
fi
echo delete-id
read
id=$1
data=`curl -sL "https://api.syui.ai/users/$id/card?itemsPerPage=2550"`
token=`cat ~/.config/atr/api_card.json|jq -r .token`
pass=`cat ~/.config/atr/api_card.json|jq -r .password`
n=`echo $data|jq length`
n=$((n - 1))
for ((i=0;i<=$n;i++))
do
card_id=`echo $data|jq -r ".[$i].id"`
echo $card
curl -X DELETE -H "Content-Type: application/json" -d "{\"owner\":$id,\"password\":\"$pass\"}" https://api.syui.ai/cards/$card_id
done
#curl -X DELETE -H "Content-Type: application/json" https://api.syui.ai/users/$id

24
scpt/card_limit.zsh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/zsh
case $OSTYPE in
darwin*)
alias date="/opt/homebrew/bin/gdate"
;;
esac
host=https://api.syui.ai
token=`cat ~/.config/atr/api_card.json|jq -r .token`
host_users="$host/users?itemsPerPage=2550"
updated_at_n=`date --iso-8601=seconds -d '1 days ago'`
#updated_at_n=`date --iso-8601=seconds`
data=`curl -sL "$host_users"|jq .`
n=`echo $data|jq length`
n=$((n - 1))
for ((i=0;i<=$n;i++))
do
name=`echo $data|jq ".[$i]"|jq -r .username`
id=`echo $data|jq ".[$i]"|jq -r .id`
echo "{\"updated_at\":\"$updated_at_n\"} -s $host/users/$id"
curl -X PATCH -H "Content-Type: application/json" -d "{\"raid_at\": \"$updated_at_n\",\"updated_at\":\"$updated_at_n\",\"token\":\"$token\",\"ten_at\":\"$updated_at_n\"}" -s $host/users/$id
done

View File

@ -6,11 +6,11 @@ import (
"context"
"net/http"
"t/ent"
"t/ent/card"
"t/ent/group"
"t/ent/ue"
"t/ent/user"
"api/ent"
"api/ent/card"
"api/ent/group"
"api/ent/ue"
"api/ent/user"
"os"
"github.com/go-faster/jx"
)