Skip to content

Commit

Permalink
feat: improve code and create access log
Browse files Browse the repository at this point in the history
  • Loading branch information
houseme committed Apr 22, 2023
1 parent 512a498 commit 66d3a1e
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 80 deletions.
14 changes: 7 additions & 7 deletions app/console/internal/controller/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type cAccount struct {
type Controller struct {
}

// New is the constructor for cAccount
func New() *cAccount {
return &cAccount{}
// New is the constructor for Controller
func New() *Controller {
return &Controller{}
}

// CreateAccount is the handler for CreateAccount
func (c *cAccount) CreateAccount(ctx context.Context, req *v1.CreateAccountReq) (res *v1.CreateAccountRes, err error) {
func (c *Controller) CreateAccount(ctx context.Context, req *v1.CreateAccountReq) (res *v1.CreateAccountRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-account-CreateAccount")
defer span.End()

Expand All @@ -39,7 +39,7 @@ func (c *cAccount) CreateAccount(ctx context.Context, req *v1.CreateAccountReq)
}

// ModifyAccount is the handler for ModifyAccount
func (c *cAccount) ModifyAccount(ctx context.Context, req *v1.ModifyAccountReq) (res *v1.ModifyAccountRes, err error) {
func (c *Controller) ModifyAccount(ctx context.Context, req *v1.ModifyAccountReq) (res *v1.ModifyAccountRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-account-ModifyAccount")
defer span.End()

Expand All @@ -51,7 +51,7 @@ func (c *cAccount) ModifyAccount(ctx context.Context, req *v1.ModifyAccountReq)
}

// ModifyPassword is the handler for ModifyPassword
func (c *cAccount) ModifyPassword(ctx context.Context, req *v1.ModifyPasswordReq) (res *v1.ModifyPasswordRes, err error) {
func (c *Controller) ModifyPassword(ctx context.Context, req *v1.ModifyPasswordReq) (res *v1.ModifyPasswordRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-account-ModifyPassword")
defer span.End()

Expand Down
12 changes: 6 additions & 6 deletions app/console/internal/controller/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type cAuth struct {
type Controller struct {
}

// New is the constructor of cAuth.
func New() *cAuth {
return &cAuth{}
// New is the constructor of Controller.
func New() *Controller {
return &Controller{}
}

// CreateAccessToken is the handler for CreateAccessToken
func (c *cAuth) CreateAccessToken(ctx context.Context, req *v1.CreateAccessTokenReq) (res *v1.CreateAccessTokenRes, err error) {
func (c *Controller) CreateAccessToken(ctx context.Context, req *v1.CreateAccessTokenReq) (res *v1.CreateAccessTokenRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-auth-CreateAccessToken")
defer span.End()

Expand All @@ -39,7 +39,7 @@ func (c *cAuth) CreateAccessToken(ctx context.Context, req *v1.CreateAccessToken
}

// Authorization is the handler for Authorization
func (c *cAuth) Authorization(ctx context.Context, req *v1.AuthReq) (res *v1.AuthRes, err error) {
func (c *Controller) Authorization(ctx context.Context, req *v1.AuthReq) (res *v1.AuthRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-auth-authorization")
defer span.End()

Expand Down
20 changes: 10 additions & 10 deletions app/console/internal/controller/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type cDomain struct {
type Controller struct {
}

// New is the constructor of cDomain.
func New() *cDomain {
return &cDomain{}
// New is the constructor of Controller.
func New() *Controller {
return &Controller{}
}

// CreateDomainAuthorization creates a new domain.
func (c *cDomain) CreateDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationReq) (res *v1.DomainAuthorizationRes, err error) {
func (c *Controller) CreateDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationReq) (res *v1.DomainAuthorizationRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-CreateDomainAuthorize")
defer span.End()

Expand All @@ -39,7 +39,7 @@ func (c *cDomain) CreateDomainAuthorization(ctx context.Context, req *v1.DomainA
}

// QueryDomainAuthorization queries the domain.
func (c *cDomain) QueryDomainAuthorization(ctx context.Context, req *v1.QueryDomainAuthorizationReq) (res *v1.QueryDomainAuthorizationRes, err error) {
func (c *Controller) QueryDomainAuthorization(ctx context.Context, req *v1.QueryDomainAuthorizationReq) (res *v1.QueryDomainAuthorizationRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-QueryDomainAuthorize")
defer span.End()

Expand All @@ -51,7 +51,7 @@ func (c *cDomain) QueryDomainAuthorization(ctx context.Context, req *v1.QueryDom
}

// UpdateDomainAuthorization updates the domain.
func (c *cDomain) UpdateDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationUpdateReq) (res *v1.DomainAuthorizationUpdateRes, err error) {
func (c *Controller) UpdateDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationUpdateReq) (res *v1.DomainAuthorizationUpdateRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-UpdateDomainAuthorize")
defer span.End()

Expand All @@ -63,7 +63,7 @@ func (c *cDomain) UpdateDomainAuthorization(ctx context.Context, req *v1.DomainA
}

// DeleteDomainAuthorization deletes the domain.
func (c *cDomain) DeleteDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationDeleteReq) (res *v1.DomainAuthorizationDeleteRes, err error) {
func (c *Controller) DeleteDomainAuthorization(ctx context.Context, req *v1.DomainAuthorizationDeleteReq) (res *v1.DomainAuthorizationDeleteRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-DeleteDomainAuthorize")
defer span.End()

Expand All @@ -75,7 +75,7 @@ func (c *cDomain) DeleteDomainAuthorization(ctx context.Context, req *v1.DomainA
}

// DomainAuthorizationList lists the domain.
func (c *cDomain) DomainAuthorizationList(ctx context.Context, req *v1.DomainAuthorizationListReq) (res *v1.DomainAuthorizationListRes, err error) {
func (c *Controller) DomainAuthorizationList(ctx context.Context, req *v1.DomainAuthorizationListReq) (res *v1.DomainAuthorizationListRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-DomainAuthorizationList")
defer span.End()

Expand All @@ -87,7 +87,7 @@ func (c *cDomain) DomainAuthorizationList(ctx context.Context, req *v1.DomainAut
}

// DomainAuthorizationDetail gets the domain.
func (c *cDomain) DomainAuthorizationDetail(ctx context.Context, req *v1.DomainAuthorizationDetailReq) (res *v1.DomainAuthorizationDetailRes, err error) {
func (c *Controller) DomainAuthorizationDetail(ctx context.Context, req *v1.DomainAuthorizationDetailReq) (res *v1.DomainAuthorizationDetailRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-domain-DomainAuthorizeDetail")
defer span.End()

Expand Down
10 changes: 5 additions & 5 deletions app/console/internal/controller/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
v1 "github.com/houseme/url-shortenter/app/console/api/echo/v1"
)

// New is the constructor of cEcho.
func New() *cEcho {
return &cEcho{}
// New is the constructor of Controller.
func New() *Controller {
return &Controller{}
}

type cEcho struct{}
type Controller struct{}

// Say is the handler for Say
func (c *cEcho) Say(ctx context.Context, req *v1.EchoSayReq) (res *v1.EchoSayRes, err error) {
func (c *Controller) Say(ctx context.Context, req *v1.EchoSayReq) (res *v1.EchoSayRes, err error) {
return &v1.EchoSayRes{Content: req.Content}, nil
}
10 changes: 5 additions & 5 deletions app/console/internal/controller/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type cHome struct {
type Controller struct {
}

// New is the constructor of cHome.
func New() *cHome {
return &cHome{}
// New is the constructor of Controller.
func New() *Controller {
return &Controller{}
}

// Index is the index page.
func (c *cHome) Index(ctx context.Context, req *v1.HomeIndexReq) (res *v1.HomeIndexRes, err error) {
func (c *Controller) Index(ctx context.Context, req *v1.HomeIndexReq) (res *v1.HomeIndexRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-home-index")
defer span.End()

Expand Down
16 changes: 8 additions & 8 deletions app/console/internal/controller/short/short.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import (
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type cShort struct {
type Controller struct {
}

// New is the constructor of cShort.
func New() *cShort {
return &cShort{}
// New is the constructor of Controller.
func New() *Controller {
return &Controller{}
}

// CreateShort is the handler for CreateShort
func (c *cShort) CreateShort(ctx context.Context, req *v1.CreateShortReq) (res *v1.CreateShortRes, err error) {
func (c *Controller) CreateShort(ctx context.Context, req *v1.CreateShortReq) (res *v1.CreateShortRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-short-CreateShort")
defer span.End()

Expand All @@ -39,7 +39,7 @@ func (c *cShort) CreateShort(ctx context.Context, req *v1.CreateShortReq) (res *
}

// ModifyShort is the handler for ModifyShort
func (c *cShort) ModifyShort(ctx context.Context, req *v1.ModifyShortReq) (res *v1.ModifyShortRes, err error) {
func (c *Controller) ModifyShort(ctx context.Context, req *v1.ModifyShortReq) (res *v1.ModifyShortRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-short-ModifyShort")
defer span.End()

Expand All @@ -51,7 +51,7 @@ func (c *cShort) ModifyShort(ctx context.Context, req *v1.ModifyShortReq) (res *
}

// QueryShort is the handler for QueryShort
func (c *cShort) QueryShort(ctx context.Context, req *v1.QueryShortReq) (res *v1.QueryShortRes, err error) {
func (c *Controller) QueryShort(ctx context.Context, req *v1.QueryShortReq) (res *v1.QueryShortRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-short-QueryShort")
defer span.End()

Expand All @@ -63,7 +63,7 @@ func (c *cShort) QueryShort(ctx context.Context, req *v1.QueryShortReq) (res *v1
}

// QueryStat is the handler for QueryStat
func (c *cShort) QueryStat(ctx context.Context, req *v1.QueryStatReq) (res *v1.QueryStatRes, err error) {
func (c *Controller) QueryStat(ctx context.Context, req *v1.QueryStatReq) (res *v1.QueryStatRes, err error) {
ctx, span := gtrace.NewSpan(ctx, "tracing-controller-short-QueryStat")
defer span.End()

Expand Down
34 changes: 34 additions & 0 deletions app/console/internal/logic/access/access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Url-Shortenter Author(https://houseme.github.io/url-shortenter/). All Rights Reserved.
*
* This Source Code Form is subject to the terms of the MIT License.
* If a copy of the MIT was not distributed with this file,
* You can obtain one at https://github.com/houseme/url-shortenter.
*/

package access

import (
"context"

"github.com/houseme/url-shortenter/app/console/internal/model"
"github.com/houseme/url-shortenter/app/console/internal/service"
)

type sAccess struct {
}

// init
func init() {
service.RegisterAccess(&sAccess{})
}

// List is the handler for List.
func (s *sAccess) List(ctx context.Context, in *model.AccessListInput) (out *model.AccessListOutput, err error) {
return
}

// Detail is the handler for Detail.
func (s *sAccess) Detail(ctx context.Context, in *model.AccessDetailInput) (out *model.AccessDetailOutput, err error) {
return
}
6 changes: 1 addition & 5 deletions app/console/internal/logic/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ type sAccount struct {
}

func init() {
service.RegisterAccount(initAccount())
}

func initAccount() *sAccount {
return &sAccount{}
service.RegisterAccount(&sAccount{})
}

// CreateAccount is the handler for CreateAccount
Expand Down
6 changes: 1 addition & 5 deletions app/console/internal/logic/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ type sAuth struct {
}

func init() {
service.RegisterAuth(initAuth())
}

func initAuth() *sAuth {
return &sAuth{}
service.RegisterAuth(&sAuth{})
}

// CreateAccessToken creates an initAuth access token.
Expand Down
6 changes: 1 addition & 5 deletions app/console/internal/logic/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ type sDomain struct {
}

func init() {
service.RegisterDomain(initDomain())
}

func initDomain() *sDomain {
return &sDomain{}
service.RegisterDomain(&sDomain{})
}

// CreateDomainAuthorize creates an initDomain domain.
Expand Down
6 changes: 1 addition & 5 deletions app/console/internal/logic/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ type sHome struct {
}

func init() {
service.RegisterHome(initHome())
}

func initHome() *sHome {
return &sHome{}
service.RegisterHome(&sHome{})
}

// Index home page.
Expand Down
1 change: 1 addition & 0 deletions app/console/internal/logic/logic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions app/console/internal/logic/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ import (
type sMiddleware struct {
}

func initMiddleware() *sMiddleware {
return &sMiddleware{}
}

func init() {
service.RegisterMiddleware(initMiddleware())
service.RegisterMiddleware(&sMiddleware{})
}

// ConsoleLogger is a middleware handler for ghttp.Request.
Expand Down
6 changes: 1 addition & 5 deletions app/console/internal/logic/short/short.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ type sShort struct {

// init
func init() {
service.RegisterShort(initShort())
}

func initShort() *sShort {
return &sShort{}
service.RegisterShort(&sShort{})
}

// CreateShort is the handler for CreateShort
Expand Down
7 changes: 1 addition & 6 deletions app/console/internal/logic/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ type sUser struct {
}

func init() {
service.RegisterUser(initUser())
}

// initUser
func initUser() *sUser {
return &sUser{}
service.RegisterUser(&sUser{})
}

// CreateMerchant creates a new merchant.
Expand Down
29 changes: 29 additions & 0 deletions app/console/internal/model/access.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Url-Shortenter Author(https://houseme.github.io/url-shortenter/). All Rights Reserved.
*
* This Source Code Form is subject to the terms of the MIT License.
* If a copy of the MIT was not distributed with this file,
* You can obtain one at https://github.com/houseme/url-shortenter.
*/

package model

// AccessListInput is the input of AccessList.
type AccessListInput struct {
// Page is the page number.
}

// AccessListOutput is the output of AccessList.
type AccessListOutput struct {
// List is the list of access.
}

// AccessDetailInput is the input of AccessDetail.
type AccessDetailInput struct {
// Id is the id of access.
}

// AccessDetailOutput is the output of AccessDetail.
type AccessDetailOutput struct {
// Access is the access.
}
Loading

0 comments on commit 66d3a1e

Please sign in to comment.