Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gf gen service command generate wrong package version #3474

Closed
johnnyzhao801 opened this issue Apr 11, 2024 · 3 comments · Fixed by #3488
Closed

gf gen service command generate wrong package version #3474

johnnyzhao801 opened this issue Apr 11, 2024 · 3 comments · Fixed by #3488
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli

Comments

@johnnyzhao801
Copy link

What version of Go and system type/arch are you using?

go1.20.5 darwin/amd64

What version of GoFrame are you using?

GF Version(go.mod):
github.com/gogf/gf/v2@v2.7.0

Can this bug be re-produced with the latest release?
yes
What did you do?

this is my logic code:

package system

import (
	"context"
	"github.com/casbin/casbin/v2"
	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
	casbinadapter "github.com/hailaz/gf-casbin-adapter/v2"
	"sync"
)

var (
	once sync.Once
	myDB gdb.DB
)

func (s *sSystem) GetEnforcer(ctx context.Context) (en *casbin.SyncedEnforcer) {
	once.Do(func() {
		en = initEnforcer(ctx)
	})
	return en
}

func initEnforcer(ctx context.Context) (en *casbin.SyncedEnforcer) {
	var err error
	link := g.Cfg().MustGet(ctx, "database.default.link")
	rbacConf := g.Cfg().MustGet(ctx, "casbin.modelFile").String()
	myDB, err = gdb.New(gdb.ConfigNode{
		Link: link.String(),
	})
	if err != nil {
		panic(err)
	}
	a := casbinadapter.NewAdapter(casbinadapter.Options{GDB: myDB})
	en, err = casbin.NewSyncedEnforcer(rbacConf, a)
	if err != nil {
		panic(err)
	}
	err = en.LoadPolicy()
	if err != nil {
		panic(err)
	}
	return
}

gf gen service

// ================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================

package service

import (
	"context"
	systemV1 "gman/api/system/v1"
	"gman/internal/model"

	"github.com/casbin/casbin"
)

type (
	ISystem interface {
		GetEnforcer(ctx context.Context) (en *casbin.SyncedEnforcer)
	}
)

var (
	localSystem ISystem
)

func System() ISystem {
	if localSystem == nil {
		panic("implement not found for interface ISystem, forgot register?")
	}
	return localSystem
}

func RegisterSystem(i ISystem) {
	localSystem = i
}

What did you expect to see?
I need casbin package:
github.com/casbin/casbin/v2

// ================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================

package service

import (
	"context"
	systemV1 "gman/api/system/v1"
	"gman/internal/model"
    
	"github.com/casbin/casbin/v2"
)

type (
	ISystem interface {
		GetEnforcer(ctx context.Context) (en *casbin.SyncedEnforcer)
	}
)

var (
	localSystem ISystem
)

func System() ISystem {
	if localSystem == nil {
		panic("implement not found for interface ISystem, forgot register?")
	}
	return localSystem
}

func RegisterSystem(i ISystem) {
	localSystem = i
}

What did you see instead?

package service

import (
	"github.com/casbin/casbin"
)
@johnnyzhao801 johnnyzhao801 added the bug It is confirmed a bug, but don't worry, we'll handle it. label Apr 11, 2024
@wln32 wln32 added the CLI about gf cli label Apr 19, 2024
@liuxgo
Copy link

liuxgo commented Oct 1, 2024

@oldme-git I already tried by v2.7.4, but the problem persists.
image

@oldme-git
Copy link
Member

@liuxgo view: #3835

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@liuxgo view: #3835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. CLI about gf cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants