-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzletest.go
80 lines (67 loc) · 2.9 KB
/
puzzletest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
*
* Copyright 2022 puzzletest authors.
*
* 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 main
import (
_ "embed"
"os"
"github.com/dvaumoron/puzzleweb"
adminservice "github.com/dvaumoron/puzzleweb/admin/service"
"github.com/dvaumoron/puzzleweb/blog"
"github.com/dvaumoron/puzzleweb/config"
"github.com/dvaumoron/puzzleweb/forum"
"github.com/dvaumoron/puzzleweb/remotewidget"
"github.com/dvaumoron/puzzleweb/wiki"
"go.uber.org/zap"
)
const wikiGroup1Id = 2
const wikiGroup2Id = 3
const blogGroupId = 4
const forumGroupId = 5
const notFound = "notFound"
//go:embed version.txt
var version string
func main() {
site, globalConfig, initSpan := puzzleweb.BuildDefaultSite(config.WebKey, version)
ctxLogger := globalConfig.CtxLogger
rightClient := globalConfig.RightClient
// create group for permissions
rightClient.RegisterGroup(wikiGroup1Id, "wikiGroup1")
rightClient.RegisterGroup(wikiGroup2Id, "wikiGroup2")
rightClient.RegisterGroup(blogGroupId, "blogGroup")
rightClient.RegisterGroup(forumGroupId, "forumGroup")
site.AddPage(puzzleweb.MakeHiddenStaticPage(globalConfig.Tracer, notFound, adminservice.PublicGroupId, notFound))
site.AddStaticPages(ctxLogger, adminservice.PublicGroupId, []string{"about/", "about/faq"})
// Warning : the object id should be different even for different kind of dynamic page
// (currently blog use forum storage for comment)
aboutPage, _ := site.GetPage("about")
faqPage, _ := aboutPage.GetSubPage("faq")
aboutPage.AddSubPage(wiki.MakeWikiPage("wiki", globalConfig.CreateWikiConfig(1, wikiGroup1Id)))
faqPage.AddSubPage(wiki.MakeWikiPage("wiki2", globalConfig.CreateWikiConfig(2, wikiGroup1Id, "Welcome", "wiki2/view", "wiki2/edit", "wiki2/list")))
site.AddPage(wiki.MakeWikiPage("wiki3", globalConfig.CreateWikiConfig(3, wikiGroup2Id)))
site.AddPage(blog.MakeBlogPage("blog", globalConfig.CreateBlogConfig(4, blogGroupId)))
site.AddPage(forum.MakeForumPage("forum", globalConfig.CreateForumConfig(5, forumGroupId)))
serviceAddr := os.Getenv("GALLERY_SERVICE_ADDR")
site.AddPage(remotewidget.MakeRemotePage("gallery", ctxLogger, "gallery", globalConfig.CreateWidgetConfig(serviceAddr, 6, adminservice.PublicGroupId)))
initSpan.End()
siteConfig := globalConfig.ExtractSiteConfig()
// emptying data no longer useful for GC cleaning
globalConfig = nil
if err := site.Run(siteConfig); err != nil {
siteConfig.Logger.Fatal("Failed to serve", zap.Error(err))
}
}