Giter Site home page Giter Site logo

gogf / focus-single Goto Github PK

View Code? Open in Web Editor NEW
142.0 5.0 49.0 6.18 MB

Single repo demo project using GoFrame.

License: GNU Lesser General Public License v3.0

Go 99.32% Dockerfile 0.16% Shell 0.02% Makefile 0.51%
goframe golang project structure demo dao dto entity orm server

focus-single's People

Contributors

gqcn avatar houseme avatar jqb44179 avatar lusson-luo avatar mingzaily avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

focus-single's Issues

项目跑起来了, 但是页面有个报错

go版本:1.18.8
gf版本: github.com/gogf/gf/v2 v2.2.1
具体报错信息 :
Template Parsing Error: template parsing failed: template: TemplateContent:1:2: executing "TemplateContent" at : error calling dump: reflect: call of reflect.Value.Type on zero Value
截图:
image

创建内容时,HTML编解码-ghtml只编码第一层,所以创建的内容中可以包含js,建议修改为ghtml.SpecialCharsMapOrStruct(&in.ContentCreateUpdateBase)

// Create 创建内容
func (s *sContent) Create(ctx context.Context, in model.ContentCreateInput) (out model.ContentCreateOutput, err error) {
if in.UserId == 0 {
in.UserId = service.BizCtx().Get(ctx).User.Id
}
// 不允许HTML代码
if err = ghtml.SpecialCharsMapOrStruct(&in.ContentCreateUpdateBase); err != nil {
return out, err
}
lastInsertID, err := dao.Content.Ctx(ctx).Data(in).InsertAndGetId()
if err != nil {
return out, err
}
return model.ContentCreateOutput{ContentId: uint(lastInsertID)}, err
}

跑不起来

[ERRO] http: panic serving [::1]:51019: exception recovered: implement not found for interface IView, forgot register?
goroutine 41 [running]:
net/http.(conn).serve.func1()
C:/Program Files/Go/src/net/http/server.go:1825 +0xbf
panic({0xc71120, 0xc002dfd4a0})
C:/Program Files/Go/src/runtime/panic.go:844 +0x258
github.com/gogf/gf/v2/net/ghttp.niceCallFunc.func1()
C:/Users/
/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_func.go:48 +0x2c8
panic({0xbca7e0, 0xf8d390})
C:/Program Files/Go/src/runtime/panic.go:838 +0x207
focus-single/internal/service.View(...)
C:/Users/
/GolandProjects/focus-single/internal/service/view.go:28
focus-single/internal/cmd.glob..func1.5(0x7)
C:/Users/
/GolandProjects/focus-single/internal/cmd/cmd.go:67 +0xba
github.com/gogf/gf/v2/net/ghttp.(Server).ServeHTTP.func2()
C:/Users/
/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_server_handler.go:161 +0x24
github.com/gogf/gf/v2/net/ghttp.niceCallFunc(0xc0003d4000?)
C:/Users/*/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_func.go:55 +0x3e
github.com/gogf/gf/v2/net/ghttp.(Server).ServeHTTP(0xc0003d4000, {0xf93490?, 0xc0000ce0e0}, 0xc00029a300)
C:/Users/
/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_server_handler.go:160 +0x55e
net/http.HandlerFunc.ServeHTTP(0x0?, {0xf93490?, 0xc0000ce0e0?}, 0xc000058c00?)
C:/Program Files/Go/src/net/http/server.go:2084 +0x2f
net/http.serverHandler.ServeHTTP({0xc002dd9fb0?}, {0xf93490, 0xc0000ce0e0}, 0xc00029a300)
C:/Program Files/Go/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc002e400a0, {0xf939b8, 0xc00068e1e0})
C:/Program Files/Go/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
C:/Program Files/Go/src/net/http/server.go:3071 +0x4db
Stack:

  1. github.com/gogf/gf/v2/net/ghttp.niceCallFunc.func1
    C:/Users/****/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_func.go:48
  2. focus-single/internal/service.View
    C:/Users/****/GolandProjects/focus-single/internal/service/view.go:28
  3. focus-single/internal/cmd.glob..func1.5
    C:/Users/****/GolandProjects/focus-single/internal/cmd/cmd.go:67
  4. github.com/gogf/gf/v2/net/ghttp.(Server).ServeHTTP.func2
    C:/Users/
    ***/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_server_handler.go:161
  5. github.com/gogf/gf/v2/net/ghttp.niceCallFunc
    C:/Users/****/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_func.go:55
  6. github.com/gogf/gf/v2/net/ghttp.(Server).ServeHTTP
    C:/Users/
    ***/go/pkg/mod/github.com/gogf/gf/[email protected]/net/ghttp/ghttp_server_handler.go:160

gf_setting表为什么不支持sqlite

Save operation is not supported by sqlite driver

func (a *cSetting) Save(ctx context.Context, req *v1.SettingSaveReq) (res *v1.SettingSaveRes, err error) {

aa := service.Setting().Set(ctx, string(req.K), string(req.V))
fmt.Println(aa)


g.Log().Info(ctx, req.K, req.V) 

g.Log().Info(ctx, "查到v值", 0)
return

}

此项目中的,数据库事务写法无效(错误)

	err = dao.User.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
		name := "testinsert1"
		var user = new(entity.User)
		user.Passport = name
		user.Password = name
		user.Nickname = name
		user.Gender = 0
		user.Avatar = name
		user.Status = 1

		_, err := dao.User.Ctx(ctx).Data(user).OmitEmpty().Save()
		if err != nil {
			return err
		}
		_, err = dao.User.Ctx(ctx).Data(user).OmitEmpty().Save()
		if err != nil {
			return err
		}
		return nil
	})

项目中的事务基本都是想上面这种写法,内嵌函数中的数据库操作并没用用到 tx *gdb.TX 而是直接用 dao.User.Ctx(ctx)

这些操作根本就不在事务中运行,所以上面这种写法,会导致第一次写入操作成功(无论第二次操作是否成功)

有效的写法:

	err = dao.User.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
		name := "testinsert1"
		var user = new(entity.User)
		user.Passport = name
		user.Password = name
		user.Nickname = name
		user.Gender = 0
		user.Avatar = name
		user.Status = 1
		_, err := tx.Insert(dao.User.Table(), user)
		if err != nil {
			return err
		}
		_, err = tx.Insert(dao.User.Table(), user)
		if err != nil {
			return err
		}
		return nil
	})


### 还有一个无效的写法(按道理说这是应该支持的写法 不支持为什么不行 应该是BUG了)

	err = dao.User.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
		name := "testinsert1"
		var user = new(entity.User)
		user.Passport = name
		user.Password = name
		user.Nickname = name
		user.Gender = 0
		user.Avatar = name
		user.Status = 1
		_, err := tx.Save(dao.User.Table(), user)
		if err != nil {
			return err
		}
		_, err = tx.Save(dao.User.Table(), user)
		if err != nil {
			return err
		}
		return nil
	})

当然 这种错误写法对单次写入操作并不影响 因为单次写入根本不需要事务

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.