Skip to content

Commit

Permalink
Merge pull request #16 from IRONICBo/main
Browse files Browse the repository at this point in the history
feat: Init project structure.
  • Loading branch information
xushiwei committed Jan 10, 2024
2 parents 3277861 + 1b4bd09 commit f35d6dd
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 16 deletions.
29 changes: 26 additions & 3 deletions cmd/gopcomm/community_yap.gox
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"
13 changes: 13 additions & 0 deletions cmd/gopcomm/config.yaml
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
43 changes: 34 additions & 9 deletions cmd/gopcomm/gop_autogen.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
package main

import "github.com/goplus/yap"
import (
"fmt"
"github.com/goplus/yap"
"github.com/goplus/community/internal/core"
)

type community struct {
yap.App
}
//line cmd/gopcomm/community_yap.gox:1
// TODO: Config Init
//
//line cmd/gopcomm/community_yap.gox:4
func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:1:1
this.Get("/p/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:2:1
ctx.Yap__1("article", map[string]string{"id": ctx.Param("id")})
//line cmd/gopcomm/community_yap.gox:4:1
config := &core.Config{core.ArticleConfig{}}
//line cmd/gopcomm/community_yap.gox:7:1
community := core.New(config)
//line cmd/gopcomm/community_yap.gox:9:1
this.Get("/article/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:10:1
param := ctx.Param("id")
//line cmd/gopcomm/community_yap.gox:11:1
fmt.Println("Visiting article " + param)
//line cmd/gopcomm/community_yap.gox:13:1
h := community.GetArticleHandler()
//line cmd/gopcomm/community_yap.gox:14:1
info, _ := h.GetArticle(param)
//line cmd/gopcomm/community_yap.gox:16:1
ctx.Yap__1("article", map[string]string{"id": info.Id, "title": info.Title, "content": info.Content})
})
//line cmd/gopcomm/community_yap.gox:6:1
//line cmd/gopcomm/community_yap.gox:22:1
this.Get("/", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:7:1
//line cmd/gopcomm/community_yap.gox:23:1
ctx.Yap__1("home", map[string]interface {
}{})
})
//line cmd/gopcomm/community_yap.gox:10:1
//line cmd/gopcomm/community_yap.gox:26:1
this.Get("/user/:id", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:27:1
ctx.Yap__1("user", map[string]string{"id": ctx.Param("id")})
})
//line cmd/gopcomm/community_yap.gox:32:1
fmt.Println("Community server running on :8080")
//line cmd/gopcomm/community_yap.gox:33:1
this.Run__1(":8080")
}
func main() {
Expand Down
5 changes: 4 additions & 1 deletion cmd/gopcomm/yap/article_yap.html
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>
8 changes: 8 additions & 0 deletions cmd/gopcomm/yap/edit_yap.html
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>
8 changes: 8 additions & 0 deletions cmd/gopcomm/yap/user_yap.html
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>
31 changes: 31 additions & 0 deletions internal/config/config.gop
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 {
}
60 changes: 60 additions & 0 deletions internal/core/article.gop
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
}
50 changes: 47 additions & 3 deletions internal/core/community.gop
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
}
79 changes: 79 additions & 0 deletions internal/core/gop_autogen.go
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)
24 changes: 24 additions & 0 deletions internal/core/models.gop
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"`
}

0 comments on commit f35d6dd

Please sign in to comment.