Skip to content

Commit

Permalink
refatct(kernal): change *kernel.ApplicationInterface to kernel.Applic…
Browse files Browse the repository at this point in the history
…ationInterface; fix wecom miniprogram GetComponent with logger
  • Loading branch information
Matrix-X committed Sep 14, 2024
1 parent 2650b82 commit 4f87327
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/kernel/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

type AccessToken struct {
App *ApplicationInterface
App ApplicationInterface

HttpHelper *helper.RequestHelper

Expand All @@ -43,8 +43,8 @@ type AccessToken struct {
GetMiddlewareOfLog func(logger contract2.LoggerInterface) contract3.RequestMiddleware
}

func NewAccessToken(app *ApplicationInterface) (*AccessToken, error) {
config := (*app).GetConfig()
func NewAccessToken(app ApplicationInterface) (*AccessToken, error) {
config := (app).GetConfig()
baseURI := config.GetString("http.base_uri", "/")

var cacheClient cache.CacheInterface = nil
Expand Down Expand Up @@ -340,8 +340,8 @@ func (accessToken *AccessToken) RegisterHttpMiddlewares() {
// log
logMiddleware := accessToken.GetMiddlewareOfLog

config := (*accessToken.App).GetConfig()
logger := (*accessToken.App).GetComponent("Logger").(contract2.LoggerInterface)
config := (accessToken.App).GetConfig()
logger := (accessToken.App).GetComponent("Logger").(contract2.LoggerInterface)
accessToken.HttpHelper.WithMiddleware(
logMiddleware(logger),
helper.HttpDebugMiddleware(config.GetBool("http_debug", false)),
Expand Down
4 changes: 2 additions & 2 deletions src/miniProgram/auth/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type AccessToken struct {
*kernel.AccessToken
}

func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {
func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(app)
token := &AccessToken{
kernelToken,
Expand All @@ -26,7 +26,7 @@ func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {

// Override GetCredentials
func (accessToken *AccessToken) OverrideGetCredentials() {
config := (*accessToken.App).GetConfig()
config := (accessToken.App).GetConfig()

accessToken.GetCredentials = func() *object.StringMap {
return &object.StringMap{
Expand Down
2 changes: 1 addition & 1 deletion src/miniProgram/auth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

func RegisterProvider(app kernel.ApplicationInterface) (*AccessToken, error) {

return NewAccessToken(&app)
return NewAccessToken(app)

}

Expand Down
4 changes: 2 additions & 2 deletions src/officialAccount/auth/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type AccessToken struct {
}

// https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {
func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(app)
if err != nil {
return nil, err
Expand All @@ -30,7 +30,7 @@ func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {

// Override GetCredentials
func (accessToken *AccessToken) OverrideGetCredentials() {
config := (*accessToken.App).GetContainer().GetConfig()
config := (accessToken.App).GetContainer().GetConfig()
accessToken.GetCredentials = func() *object.StringMap {
return &object.StringMap{
"grant_type": "client_credential",
Expand Down
2 changes: 1 addition & 1 deletion src/officialAccount/auth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (

func RegisterProvider(app kernel.ApplicationInterface) (*AccessToken, error) {

return NewAccessToken(&app)
return NewAccessToken(app)

}
6 changes: 3 additions & 3 deletions src/openPlatform/auth/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AccessToken struct {
}

// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_access_token.html
func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {
func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(app)

kernelToken.RequestMethod = http.MethodPost
Expand All @@ -37,8 +37,8 @@ func NewAccessToken(app *kernel.ApplicationInterface) (*AccessToken, error) {
func (accessToken *AccessToken) OverrideGetCredentials() {

accessToken.GetCredentials = func() *object.StringMap {
config := (*accessToken.App).GetContainer().GetConfig()
verifyTicket := (*accessToken.App).GetComponent("VerifyTicket").(*VerifyTicket)
config := (accessToken.App).GetContainer().GetConfig()
verifyTicket := (accessToken.App).GetComponent("VerifyTicket").(*VerifyTicket)
ticket, _ := verifyTicket.GetTicket()

return &object.StringMap{
Expand Down
2 changes: 1 addition & 1 deletion src/openPlatform/auth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func RegisterProvider(app kernel.ApplicationInterface) (*VerifyTicket, *AccessToken, error) {

ticket, err := NewVerifyTicket(&app)
accessToken, err := NewAccessToken(&app)
accessToken, err := NewAccessToken(app)

return ticket, accessToken, err

Expand Down
4 changes: 2 additions & 2 deletions src/openPlatform/authorizer/auth/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type AccessToken struct {

// https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
func NewAccessToken(app kernel.ApplicationInterface, component kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(&app)
kernelToken, err := kernel.NewAccessToken(app)

kernelToken.RequestMethod = http.MethodPost
kernelToken.QueryName = "access_token"
Expand All @@ -46,7 +46,7 @@ func (accessToken *AccessToken) OverrideGetCredentials() {

accessToken.GetCredentials = func() *object.StringMap {

config := (*accessToken.App).GetContainer().GetConfig()
config := (accessToken.App).GetContainer().GetConfig()
componentConfig := accessToken.Component.GetContainer().GetConfig()
return &object.StringMap{
"component_appid": (*componentConfig)["app_id"].(string),
Expand Down
4 changes: 2 additions & 2 deletions src/work/auth/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AccessToken struct {

// https://developer.work.weixin.qq.com/document/path/91039
func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {
kernelToken, err := kernel.NewAccessToken(&app)
kernelToken, err := kernel.NewAccessToken(app)
if err != nil {
return nil, err
}
Expand All @@ -30,7 +30,7 @@ func NewAccessToken(app kernel.ApplicationInterface) (*AccessToken, error) {

// Override GetCredentials
func (accessToken *AccessToken) OverrideGetCredentials() {
config := (*accessToken.App).GetConfig()
config := (accessToken.App).GetConfig()
corpID := config.GetString("corp_id", "")
secret := config.GetString("secret", "")
accessToken.GetCredentials = func() *object.StringMap {
Expand Down
3 changes: 3 additions & 0 deletions src/work/miniProgram/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type Application struct {
kernel.ApplicationInterface
*miniProgram.MiniProgram

AccessToken *auth.AccessToken
Expand Down Expand Up @@ -86,6 +87,8 @@ func (app *Application) GetComponent(name string) interface{} {
return app.Auth
case "Config":
return app.Config
case "Logger":
return app.Logger

default:
return nil
Expand Down

0 comments on commit 4f87327

Please sign in to comment.