-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from IRONICBo/main
feat: Init project structure.
- Loading branch information
Showing
11 changed files
with
334 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
get "/p/:id", ctx => { | ||
import "github.com/goplus/community/internal/core" | ||
|
||
// TODO: Config Init | ||
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": ctx.param("id"), | ||
"id": info.Id, | ||
"title": info.Title, | ||
"content": info.Content, | ||
} | ||
} | ||
get "/", ctx => { | ||
ctx.yap "home", {} | ||
ctx.yap "home", { | ||
} | ||
} | ||
get "/user/:id", ctx => { | ||
ctx.yap "user", { | ||
"id": ctx.param("id"), | ||
} | ||
} | ||
|
||
println "Community server running on :8080" | ||
run ":8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
app: | ||
version: 0.0.1 | ||
debug: true | ||
log_file: /var/log/gopcomm.log | ||
server: | ||
ip: 0.0.0.0 | ||
port: 8080 | ||
mysql: | ||
ip: 127.0.0.1 | ||
port: 6379 | ||
username: root | ||
password: goplus | ||
database: community |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
|
||
</head> | ||
<body> | ||
Article {{.id}} | ||
<span>Article {{.id}}</span> | ||
<h1>Title {{.title}}</h1> | ||
<p>Content {{.content}}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
Markdown Edit Page. | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
User {{.id}}. | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
//Config contains all application configurations in goplus community | ||
type Config struct { | ||
App | ||
Database | ||
} | ||
|
||
//App contains application configurations | ||
type App struct { | ||
} | ||
|
||
// Database contains database configurations | ||
type Database struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package core | ||
|
||
// Check interface implementation. | ||
var _ articleHandler = (*articleHandlerImpl)(nil) | ||
|
||
// Article Config | ||
// | ||
// ArticleConfig is the config for article. | ||
type ArticleConfig struct { | ||
} | ||
|
||
// articleHandler | ||
// | ||
// articleHandler is the interface for article handler, | ||
// which defines the methods that must be implemented by the article handler. | ||
// We need to implement this interface in the community/internal/core package. | ||
type articleHandler interface { | ||
GetArticle(id string) (Article, error) | ||
} | ||
|
||
// ArticleHandler | ||
// | ||
// ArticleHandler is the handler for article. | ||
type articleHandlerImpl struct { | ||
config *ArticleConfig | ||
} | ||
|
||
// NewArticleHandler creates a new article handler. | ||
func newArticleHandler(conf *ArticleConfig) *articleHandlerImpl { | ||
return &articleHandlerImpl{ | ||
config: conf, | ||
} | ||
} | ||
|
||
// GetArticle gets article by id. | ||
func (h *articleHandlerImpl) GetArticle(id string) (Article, error) { | ||
// TODO: get data from db. | ||
|
||
return Article{ | ||
Id: id, | ||
Title: "Goplus Community Article Content: " + string(id), | ||
Content: "Goplus Community Article Content: " + string(id), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package core | ||
|
||
// Check interface implementation. | ||
var _ communityHandler = (*communityHandlerImpl)(nil) | ||
|
||
// Config | ||
// | ||
// Top level config for community handlers. | ||
type Config struct { | ||
ArticleConfig | ||
} | ||
|
||
type Community struct { | ||
// communityHandler | ||
// | ||
// communityHandler is the interface for community handler, | ||
// which defines the methods that must be implemented by the community handler. | ||
// It returns the handler for each service. | ||
type communityHandler interface { | ||
GetArticleHandler() articleHandler | ||
} | ||
|
||
func New(conf *Config) *Community { | ||
return &Community{} | ||
// CommunityHandler | ||
// | ||
// CommunityHandler is the top handler for community. | ||
// It contains all the handlers for each service. | ||
type communityHandlerImpl struct { | ||
articleHandler | ||
} | ||
|
||
// New creates a new community handler. | ||
func New(conf *Config) *communityHandlerImpl { | ||
return &communityHandlerImpl{ | ||
articleHandler: newArticleHandler(&conf.ArticleConfig), | ||
} | ||
} | ||
|
||
// GetArticleHandler gets article handler. | ||
func (p *communityHandlerImpl) GetArticleHandler() articleHandler { | ||
return p.articleHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package core | ||
// Article Config | ||
// | ||
// ArticleConfig is the config for article. | ||
type ArticleConfig struct { | ||
} | ||
// articleHandler | ||
// | ||
// articleHandler is the interface for article handler, | ||
// which defines the methods that must be implemented by the article handler. | ||
// We need to implement this interface in the community/internal/core package. | ||
type articleHandler interface { | ||
GetArticle(id string) (Article, error) | ||
} | ||
// ArticleHandler | ||
// | ||
// ArticleHandler is the handler for article. | ||
type articleHandlerImpl struct { | ||
config *ArticleConfig | ||
} | ||
// Config | ||
// | ||
// Top level config for community handlers. | ||
type Config struct { | ||
ArticleConfig | ||
} | ||
// communityHandler | ||
// | ||
// communityHandler is the interface for community handler, | ||
// which defines the methods that must be implemented by the community handler. | ||
// It returns the handler for each service. | ||
type communityHandler interface { | ||
GetArticleHandler() articleHandler | ||
} | ||
// CommunityHandler | ||
// | ||
// CommunityHandler is the top handler for community. | ||
// It contains all the handlers for each service. | ||
type communityHandlerImpl struct { | ||
articleHandler | ||
} | ||
//Article Article struct | ||
type Article struct { | ||
Id string `json:"id"` | ||
Title string `json:"title"` | ||
Content string `json:"content"` | ||
} | ||
// GetArticle gets article by id. | ||
// | ||
//line internal/core/article.gop:52:1 | ||
func (h *articleHandlerImpl) GetArticle(id string) (Article, error) { | ||
//line internal/core/article.gop:55:1 | ||
return Article{Id: id, Title: "Goplus Community Article Content: " + string(id), Content: "Goplus Community Article Content: " + string(id)}, nil | ||
} | ||
// NewArticleHandler creates a new article handler. | ||
// | ||
//line internal/core/article.gop:45:1 | ||
func newArticleHandler(conf *ArticleConfig) *articleHandlerImpl { | ||
//line internal/core/article.gop:46:1 | ||
return &articleHandlerImpl{config: conf} | ||
} | ||
// GetArticleHandler gets article handler. | ||
// | ||
//line internal/core/community.gop:54:1 | ||
func (p *communityHandlerImpl) GetArticleHandler() articleHandler { | ||
//line internal/core/community.gop:55:1 | ||
return p.articleHandler | ||
} | ||
// New creates a new community handler. | ||
// | ||
//line internal/core/community.gop:47:1 | ||
func New(conf *Config) *communityHandlerImpl { | ||
//line internal/core/community.gop:48:1 | ||
return &communityHandlerImpl{articleHandler: newArticleHandler(&conf.ArticleConfig)} | ||
} | ||
// Check interface implementation. | ||
var _ articleHandler = (*articleHandlerImpl)(nil) | ||
// Check interface implementation. | ||
var _ communityHandler = (*communityHandlerImpl)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package core | ||
|
||
//Article Article struct | ||
type Article struct { | ||
Id string `json:"id"` | ||
Title string `json:"title"` | ||
Content string `json:"content"` | ||
} |