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

feat: Init project structure. #16

Merged
merged 5 commits into from
Jan 10, 2024
Merged

feat: Init project structure. #16

merged 5 commits into from
Jan 10, 2024

Conversation

IRONICBo
Copy link
Collaborator

@IRONICBo IRONICBo commented Jan 8, 2024

Init basic goplus community project structure. Still in progress :)

@IRONICBo IRONICBo marked this pull request as draft January 8, 2024 23:28
cmd/gopcomm/community_yap.gox Outdated Show resolved Hide resolved
cmd/gopcomm/internal/config/config.gop Outdated Show resolved Hide resolved
@IRONICBo
Copy link
Collaborator Author

IRONICBo commented Jan 10, 2024

Run with core function and interact with data.

gopcomm % gop run .
Community server running on :8080
Visiting article 10
image

@IRONICBo
Copy link
Collaborator Author

Project structure.

.
├── LICENSE
├── README.md
├── cmd
│   └── gopcomm
│       ├── community_yap.gox
│       ├── config.yaml
│       ├── gop_autogen.go
│       └── yap
│           ├── article_yap.html
│           ├── edit_yap.html
│           ├── home_yap.html
│           ├── static
│           └── user_yap.html
├── docs
│   ├── account-design.md
│   ├── distribute-design.md
│   ├── markdown-design.md
│   ├── mysql-framework.md
│   ├── share-design.md
│   └── web-framework.md
├── go.mod
├── go.sum
└── internal
    ├── config
    │   └── config.gop
    └── core
        ├── article.gop
        ├── community.gop
        ├── gop_autogen.go
        └── models.gop

@IRONICBo IRONICBo marked this pull request as ready for review January 10, 2024 01:12
@IRONICBo
Copy link
Collaborator Author

Design

DOM-like Core Handlers Design

Top core handler

communityHandler define a top interface for community handler, it will return all the handlers for community.

type communityHandler interface {
	GetArticleHandler() articleHandler
}

Use var _ communityHandler = (*communityHandlerImpl)(nil) to check if the communityHandlerImpl implement the communityHandler interface.

Article handler

articleHandler define a series of method to get article in inteface. The articleHandlerImpl implement the articleHandler interface.

All sub handlers(like articleHandlerImpl, articleHandler) are private, only the top handler(function New()) is public. Developers can only use the top handler to get all the sub handlers, and use the sub handlers to get the specific operation.

type articleHandler interface {
	GetArticle(id string) (Article, error)
}

Config Design

Config is a struct to store the config of community, in core package, it will be used to init the community handler and all sub handlers.

In config package, it will be used to load the config from file or env, and used for community system.

View Design

View(router) is used to store the view of community in cmd/gopcomm package, it will be used to init the web server handlers and routers.

Core web-framework is powered by yap(goplus web classfile), we need to define the routers to handle the request, and get top handler from core package.

In each router, we will get the top handler from core package, and use the top handler to get the sub handler, and use the sub handler to handle the request.

config := &core.Config{
	core.ArticleConfig{},
}
community := core.New(config)

get "/article/:id", ctx => {
	param := ctx.param("id")
	println "Visiting article " + param

	h := community.GetArticleHandler()
	info, _ := h.GetArticle(param)

	ctx.yap "article", {
		"id": info.Id,
		"title": info.Title,
		"content": info.Content,
	}
}

@IRONICBo IRONICBo requested a review from xushiwei January 10, 2024 03:18
@xushiwei xushiwei merged commit f35d6dd into goplus:main Jan 10, 2024
6 checks passed
Baihhh referenced this pull request in Baihhh/community Jan 23, 2024
bugfix: fix the bug in cloning specific branch
wu-jj pushed a commit to wu-jj/community that referenced this pull request Jan 24, 2024
bugfix: fix the bug in cloning specific branch
IRONICBo pushed a commit that referenced this pull request Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants