forked from goffee/core
Compare commits
7 commits
Author | SHA1 | Date | |
---|---|---|---|
1b23363f6f | |||
0db37d31b8 | |||
deb119db84 | |||
b274d3268f | |||
4968da25f3 | |||
0afafd8c41 | |||
90564daa5b |
9 changed files with 97 additions and 8 deletions
|
@ -22,6 +22,10 @@ type GormConfig struct {
|
|||
EnableGorm bool
|
||||
}
|
||||
|
||||
type QueueConfig struct {
|
||||
EnableQueue bool
|
||||
}
|
||||
|
||||
type CacheConfig struct {
|
||||
EnableCache bool
|
||||
}
|
||||
|
|
14
context.go
14
context.go
|
@ -19,6 +19,7 @@ import (
|
|||
"syscall"
|
||||
|
||||
"git.smarteching.com/goffee/core/logger"
|
||||
"github.com/hibiken/asynq"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -68,8 +69,9 @@ func (c *Context) RequestParamExists(key string) bool {
|
|||
return c.Request.httpRequest.Form.Has(key)
|
||||
}
|
||||
|
||||
func (c *Context) GetRequesForm() interface{} {
|
||||
return c.Request.httpRequest.Form
|
||||
func (c *Context) GetRequesForm(key string) interface{} {
|
||||
c.Request.httpRequest.ParseForm()
|
||||
return c.Request.httpRequest.Form[key]
|
||||
}
|
||||
|
||||
func (c *Context) GetRequesBodyMap() map[string]interface{} {
|
||||
|
@ -111,6 +113,14 @@ func (c *Context) GetCookie() (UserCookie, error) {
|
|||
return user, nil
|
||||
}
|
||||
|
||||
func (c *Context) GetQueueClient() *asynq.Client {
|
||||
|
||||
redisAddr := fmt.Sprintf("%v:%v", os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))
|
||||
client := asynq.NewClient(asynq.RedisClientOpt{Addr: redisAddr})
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Context) GetUploadedFile(name string) *UploadedFileInfo {
|
||||
file, fileHeader, err := c.Request.httpRequest.FormFile(name)
|
||||
if err != nil {
|
||||
|
|
10
go.mod
10
go.mod
|
@ -10,11 +10,11 @@ require (
|
|||
git.smarteching.com/zeni/go-chart/v2 v2.1.4
|
||||
github.com/brianvoe/gofakeit/v6 v6.21.0
|
||||
github.com/golang-jwt/jwt/v5 v5.0.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/harranali/mailing v1.2.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/redis/go-redis/v9 v9.0.5
|
||||
github.com/redis/go-redis/v9 v9.7.0
|
||||
golang.org/x/crypto v0.11.0
|
||||
gorm.io/driver/mysql v1.5.1
|
||||
gorm.io/driver/postgres v1.5.2
|
||||
|
@ -28,6 +28,7 @@ require (
|
|||
github.com/go-chi/chi/v5 v5.0.8 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/hibiken/asynq v0.25.1 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||
github.com/jackc/pgx/v5 v5.3.1 // indirect
|
||||
|
@ -37,11 +38,16 @@ require (
|
|||
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.9.1 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sendgrid/rest v2.6.9+incompatible // indirect
|
||||
github.com/sendgrid/sendgrid-go v3.12.0+incompatible // indirect
|
||||
github.com/spf13/cast v1.7.0 // indirect
|
||||
golang.org/x/image v0.21.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
google.golang.org/protobuf v1.35.2 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
16
go.sum
16
go.sum
|
@ -40,8 +40,12 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw
|
|||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/harranali/mailing v1.2.0 h1:ihIyJwB8hyRVcdk+v465wk1PHMrSrgJqo/kMd+gZClY=
|
||||
github.com/harranali/mailing v1.2.0/go.mod h1:4a5N3yG98pZKluMpmcYlTtll7bisvOfGQEMIng3VQk4=
|
||||
github.com/hibiken/asynq v0.25.1 h1:phj028N0nm15n8O2ims+IvJ2gz4k2auvermngh9JhTw=
|
||||
github.com/hibiken/asynq v0.25.1/go.mod h1:pazWNOLBu0FEynQRBvHA26qdIKRSmfdIfUm4HdsLmXg=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||
|
@ -79,11 +83,17 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
|
||||
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
|
||||
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
||||
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekueiEMJ7NEoxJo0=
|
||||
github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
|
||||
github.com/sendgrid/sendgrid-go v3.12.0+incompatible h1:/N2vx18Fg1KmQOh6zESc5FJB8pYwt5QFBDflYPh1KVg=
|
||||
github.com/sendgrid/sendgrid-go v3.12.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
|
||||
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
|
||||
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf/go.mod h1:RJID2RhlZKId02nZ62WenDCkgHFerpIOmW0iT7GKmXM=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
|
@ -99,11 +109,17 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
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/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
49
queue.go
Normal file
49
queue.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2025 Zeni Kim <zenik@smarteching.com>
|
||||
// Use of this source code is governed by MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
type Asynqtask func(context.Context, *asynq.Task) error
|
||||
|
||||
type Queuemux struct {
|
||||
themux *asynq.ServeMux
|
||||
}
|
||||
|
||||
func (q *Queuemux) QueueInit() {
|
||||
q.themux = asynq.NewServeMux()
|
||||
}
|
||||
|
||||
func (q *Queuemux) AddWork(pattern string, work Asynqtask) {
|
||||
q.themux.HandleFunc(pattern, work)
|
||||
}
|
||||
|
||||
func (q *Queuemux) RunQueueserver() {
|
||||
|
||||
redisAddr := fmt.Sprintf("%v:%v", os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))
|
||||
|
||||
srv := asynq.NewServer(
|
||||
asynq.RedisClientOpt{Addr: redisAddr},
|
||||
asynq.Config{Concurrency: 10,
|
||||
// Optionally specify multiple queues with different priority.
|
||||
Queues: map[string]int{
|
||||
"critical": 6,
|
||||
"default": 3,
|
||||
"low": 1,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
if err := srv.Run(q.themux); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -28,10 +28,10 @@ type header struct {
|
|||
}
|
||||
|
||||
// TODO add doc
|
||||
func (rs *Response) BufferPDF(name string, b bytes.Buffer) *Response {
|
||||
func (rs *Response) BufferFile(name string, filetype string, b bytes.Buffer) *Response {
|
||||
|
||||
if rs.isTerminated == false {
|
||||
rs.HttpResponseWriter.Header().Add("Content-Type", "application/pdf")
|
||||
rs.HttpResponseWriter.Header().Add("Content-Type", filetype)
|
||||
rs.HttpResponseWriter.Header().Add("Content-Disposition", "attachment; filename="+name)
|
||||
b.WriteTo(rs.HttpResponseWriter)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ type ContentTable struct {
|
|||
|
||||
type ContentTableTH struct {
|
||||
ID string
|
||||
ValueType string // -> default string, href, badge
|
||||
ValueType string // -> default string, href, badge, list, checkbox
|
||||
Value string
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
{{template "content_href" $item.Value}}
|
||||
{{ else if eq $x.ValueType "badge"}}
|
||||
{{template "content_badge" $item.Value}}
|
||||
{{ else if eq $x.ValueType "list"}}
|
||||
{{template "content_list" $item.Value}}
|
||||
{{ else if eq $x.ValueType "checkbox"}}
|
||||
{{template "form_checkbox" $item.Value}}
|
||||
{{ else }}
|
||||
{{ $item.Value }}
|
||||
{{end}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{define "form_checkbox"}}
|
||||
<div class="input-container">
|
||||
<label class="form-label">{{.Label}}</label>
|
||||
{{ if .Label }}<label class="form-label">{{.Label}}</label>{{end}}
|
||||
{{range $options := .AllCheckbox}}
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="{{$options.Name}}" id="{{$options.ID}}" value="{{$options.Value}}"{{if eq $options.IsChecked true}} checked{{end}}>
|
||||
|
|
Loading…
Reference in a new issue