一个基于gfast框架的组团学习网站实现,代码已开源

计划是做一个基于翻转课堂实现的学习分享社区,让学习充满乐趣!互联网有很多的学习资源,如何提高自主学习的效率,用有限的时间快速的完成高质量的学习,窃以为以教为学,翻转课堂的学习方法是当前最有效解决这个问题的方法,所以考虑做一个基于翻转课堂实现的学习分享社区,以提高自主学习的质量;

 

围绕学习课程主题来展开,主题可以是一门编程语言,一本书(电子书或者字纸书均可),一个视频课程资源,互联网有很多的学习资源,如何提高自主学习的效率,用有限的时间快速的完成高质量的学习,以教为学,翻转课堂的学习方法自认为是有效解决自主学习效率的问题,所以考虑做一个一个基于翻转课堂实现的学习分享社区;

 最小原型思维导图如下:

一个基于gfast框架的组团学习网站实现,代码已开源_第1张图片

想得有点大,本来想做一个翻转课堂的工具型站,包括笔记、音视频、题库,做着做着就发现没那么容易,一个人毕竟精力有限,看群里有同学分享一个群组 todo 的网站,还是有前端经验的同学出来的效果好,做了两个月,现在来看只能算是能用,近期刚好在学习 Go,后端是基于 Go 的框架,使用gframe的框架,代码也开放出来,有兴趣的同学来玩;

 

-------------

 

测试站点:https://pub6.top/

 

代码提交 github: https://github.com/twoconk/pub6.git

 

开放的代码对于理解gf框架,练习Go语法是足够的,总结的话,主要有几点:

1. 第一个是数据库操作,关联表查询;

2. 用户token认证;

3. 应该是session context数据共享,但并没有深入去用;

4. 前端layui数据共享,页面跳转,缓存冲突,重要的草稿功能;

 

1、Gframe框架参考文档网站: https://itician.org/pages/viewpage.action?pageId=1114145

主要需要理解GFrame的框架设计思路,目录结构,和常用的api的使用方法;

 

2、设计数据库和表结构,生成对应的model文件,在gfast的路径下,使用的命令是gf gen命令生成model代码;

gf gen model ./app/model/topic -t 业务表名

 在线生成业务表的controller、service代码,并拷贝到相应目录;

 

数据库设计:

这里面有点复杂的就是题库的设计,题库的生成和答卷的记录;可以见data路径下的sql文件;

 

3、路由设计:

修改routerAdmin.go 注意:这个group放在哪个更路径下//扩展业务

group.Group("/module", func(group *ghttp.RouterGroup) {

group.ALL("/xxx", new(module.xxx))

})

非登录状态下使用的api


group := s.Group("/")

//api

globaltopicTask := new (topic.Task)

group.POST("/pub6/topic/tasks", globaltopicTask.List)



globaltopicMembers := new (topic.Members)

group.POST("/pub6/topic/members", globaltopicMembers.List)



globaltopicNotes := new (topic.Notes)

group.POST("/pub6/topic/notes", globaltopicNotes.List)



globaltopicNotices := new (topic.Notices)

group.POST("/pub6/topic/notices", globaltopicNotices.List)



globaltopicResources := new (topic.Resource)

group.POST("/pub6/topic/resources", globaltopicResources.List)



globaltopic := new(topic.Topic)

group.POST("/pub6/topic/all", globaltopic.List)

group.POST("/pub6/topic/type", globaltopic.ListByType)

group.GET("/pub6/topic/getcomments”, globaltopic.CommentList)

group.GET("/pub6/topic/get", globaltopic.Edit)

group.POST("/pub6/topic/category", globaltopic.Catgory)



globaluser := new(topic.Users)

group.POST("/pub6/user/reg", globaluser.Add)

登录状态下使用系统api


group := s.Group("/")

//api



group.Group("/api.v2", func(group *ghttp.RouterGroup) {

group.ALL("/csrf", func(r *ghttp.Request) {

r.Response.Writeln(r.Method + ": " + r.RequestURI)

})

/*

group.Middleware(csrf.NewWithCfg(csrf.Config{

Cookie: &http.Cookie{

Name: "_csrf",// token name in cookie

},

ExpireTime:      time.Hour * 24,

TokenLength:     32,

TokenRequestKey: "X-Token",// use this key to read token in request param

}))

*/



group.Middleware(middleWare.UserAuth) //后台权限验证

group.ALL("/topic", new(topic.Topic))

group.ALL("/topicresource", new (topic.Resource))

group.ALL("/topictask", new (topic.Task))

group.ALL("/topicmembers", new (topic.Members))

group.ALL("/topictaskprogress", new (topic.Taskprogress))

group.ALL("/topicnotes", new (topic.Notes))

group.ALL("/topicntices", new (topic.Notices))

group.ALL("/user", new(topic.Users))

group.ALL("/question", new(topic.Questions))

group.ALL("/questionhistory", new(topic.History))

group.ALL("/questionhistorydetail", new(topic.Detail))

group.ALL("/booklist", new (topic.BookResource))

group.ALL("/bookcatetory", new (topic.Category))





})

其实登陆这块的逻辑还是有些复杂的,代码主要在library/service/topicService.go;为了和admin的登陆token认证分隔开,需要在boot路径下注册gftoken:



var TopicGfToken *gtoken.GfToken

func initTopic() {
	//无需验证权限的用户id
	service.NotCheckAuthAdminIds = g.Cfg().GetInts("adminInfo.notCheckAuthAdminIds")
	//后端分页长度配置
	service.AdminPageNum = g.Cfg().GetInt("adminInfo.pageNum")
	// 设置并启动后台gtoken处理
	initTopicGfToken()
}

func initTopicGfToken() {
    //多端登陆配置 
    TopicGfToken = >oken.GfToken{
        CacheMode:        g.Cfg().GetInt8("gToken.CacheMode"),
        CacheKey:         g.Cfg().GetString("gToken.CacheKey"),
        Timeout:          g.Cfg().GetInt("gToken.Timeout"),
        MaxRefresh:       g.Cfg().GetInt("gToken.MaxRefresh"),
        TokenDelimiter:   g.Cfg().GetString("gToken.TokenDelimiter"),
        EncryptKey:       g.Cfg().GetBytes("gToken.EncryptKey"),
        AuthFailMsg:      g.Cfg().GetString("gToken.AuthFailMsg"),
        MultiLogin:       true,
        LoginPath:        "/pub6Login/login",
        LoginBeforeFunc:  service.UserLogin,
        LoginAfterFunc:   service.UserLoginAfter,
        LogoutPath:       "/pub6Login/logout",
        AuthPaths:        g.SliceStr{"/api.v2/*"},
        AuthAfterFunc:    service.AuthAfterFunc,
        LogoutBeforeFunc: service.LoginOut,
    }
    TopicGfToken.Start()
}


 

4、使用https://127.0.0.1:8200/访问并验证

你可能感兴趣的:(后台服务,go,sql,gfast,组团学习)