当前位置: 首页 > news >正文

网站开发商品管理图书馆门户网站建设总结

网站开发商品管理,图书馆门户网站建设总结,win7在iis中新建一个网站,工商网站查询个人信息在诸如广告、推荐等系统中#xff0c;我们往往会涉及过滤、召回和排序等过程。随着系统业务变得复杂#xff0c;代码的耦合和交错会让项目跌入难以维护的深渊。于是模块化设计是复杂系统的必备基础。这篇文章介绍的业务框架脱胎于线上多人协作开发、高并发的竞价广告系统我们往往会涉及过滤、召回和排序等过程。随着系统业务变得复杂代码的耦合和交错会让项目跌入难以维护的深渊。于是模块化设计是复杂系统的必备基础。这篇文章介绍的业务框架脱胎于线上多人协作开发、高并发的竞价广告系统在实践中不停被优化直到易于理解和应用。 基础组件 Handler 在系统中我们定义一个独立的业务逻辑为一个Handler。 比如过滤“机型”信息的逻辑可以叫做DeviceFilterHandler排序的逻辑叫SortHandler。 Handler的实现也很简单只要实现frame.HandlerBaseInterface接口和它对应的方法即可见github package mainimport (fmtghgroups/frameghgroupscontext ghgroups/frame/ghgroups_contextreflect )type ExampleHandler struct {frame.HandlerBaseInterface }func NewExampleHandler() *ExampleHandler {return ExampleHandler{} }// /// // ConcreteInterface func (e *ExampleHandler) Name() string {return reflect.TypeOf(*e).Name() }// /// // HandlerBaseInterface func (e *ExampleHandler) Handle(*ghgroupscontext.GhGroupsContext) bool {fmt.Printf(run %s, e.Name())return true } ConcreteInterface 在系统中我们要求每个组件都要有名字。这样我们可以在配置文件中指定它在流程中的具体位置。 组件通过继承接口ConcreteInterface并实现其Name方法来暴露自己的名称。它可以被写死如上例也可以通过配置文件来指定见后续案例。 type ConcreteInterface interface {Name() string }HandlerBaseInterface 处理业务逻辑的代码需要在Handle(context *ghgroupscontext.GhGroupsContext) bool中实现的。上例中我们只让其输出一行文本。 这个方法来源于HandlerBaseInterface接口。 type HandlerBaseInterface interface {ConcreteInterfaceHandle(context *ghgroupscontext.GhGroupsContext) bool }因为HandlerBaseInterface 继承自ConcreteInterface 所以我们只要让自己构建的Handler继承自HandlerBaseInterface并实现相应方法即可。 应用 一般一个复杂的业务不能只有一个Handler但是为了便于方便讲解我们看下怎么运行只有一个Handler的框架见github。 package mainimport (fmtghgroups/frameghgroups/frame/constructorghgroupscontext ghgroups/frame/ghgroups_contextghgroups/frame/utilsreflect )func main() {constructor : utils.BuildConstructor()constructor.Register(reflect.TypeOf(ExampleHandler{}))mainProcess : reflect.TypeOf(ExampleHandler{}).Name()run(constructor, mainProcess) }func run(constructor *constructor.Constructor, mainProcess string) {if err : constructor.CreateConcrete(mainProcess); err ! nil {fmt.Printf(%v, err)}if someInterfaced, err : constructor.GetConcrete(mainProcess); err ! nil {fmt.Printf(%v, err)} else {if mainHandlerGroup, ok : someInterfaced.(frame.HandlerBaseInterface); !ok {fmt.Printf(mainHandlerGroup %s is not frame.HandlerBaseInterface, mainProcess)} else {context : ghgroupscontext.NewGhGroupsContext(nil)// context.ShowDuration truemainHandlerGroup.Handle(context)}} }在main函数中我们需要向对象构建器constructor注册我们写的Handler。然后调用run方法传入构建器和需要启动的组件名mainProcess即可。运行结果如下 ExampleHandler run ExampleHandler第一行是框架打印的流程图目前只有一个第二行是运行时ExampleHandler的Handle方法的执行结果。 HandlerGroup HandlerGroup是一组串行执行的Handler。 框架底层已经实现好了HandlerGroup的代码我们只要把每个Handler实现即可Handler的代码可以前面的例子。 然后在配置文件中配置好Handler的执行顺序 name: handler_group_a type: HandlerGroup handlers: - ExampleAHandler- ExampleBHandler应用 部分代码如下完整见github package mainimport (fmtghgroups/frameghgroups/frame/constructorconstructorbuilder ghgroups/frame/constructor_builderghgroups/frame/factoryghgroupscontext ghgroups/frame/ghgroups_contextospathreflect )func main() {factory : factory.NewFactory()factory.Register(reflect.TypeOf(ExampleAHandler{}))factory.Register(reflect.TypeOf(ExampleBHandler{}))runPath, errGetWd : os.Getwd()if errGetWd ! nil {fmt.Printf(%v, errGetWd)return}concretePath : path.Join(runPath, conf)constructor : constructorbuilder.BuildConstructor(factory, concretePath)mainProcess : handler_group_arun(constructor, mainProcess) }这次对象构建器我们需要使用constructorbuilder.BuildConstructor去构建。因为其底层会通过配置文件所在的文件夹路径concretePath 构建所有的组件。而在此之前需要告诉构建器还有两个我们自定义的组件ExampleAHandler和ExampleBHandler需要注册到系统中。于是我们暴露出对象工厂factory 用于提前注册。 运行结果如下 handler_group_aExampleAHandlerExampleBHandler run ExampleAHandler run ExampleBHandler前三行是配置文件描述的执行流程。后两行是实际执行流程中的输出。 AsyncHandlerGroup AsyncHandlerGroup是一组并行执行的Handler。 和HandlerGroup一样框架已经实现了AsyncHandlerGroup的底层代码我们只用实现各个Handler即可。 有别于HandlerGroup它需要将配置文件中的type设置为AsyncHandlerGroup。 name: async_handler_group_a type: AsyncHandlerGroup handlers: - ExampleAHandler- ExampleBHandler应用 使用的代码和HandlerGroup类似具体见github。 执行结果如下 async_handler_group_aExampleAHandlerExampleBHandler run ExampleBHandler run ExampleAHandlerLayer Layer由两部分组成Divider和Handler。Handler是一组业务逻辑Divider用于选择执行哪个Handler。 Divider 不同于HandlerDivider需要继承和实现DividerBaseInterface接口。 type DividerBaseInterface interface {ConcreteInterfaceSelect(context *ghgroupscontext.GhGroupsContext) string }Select方法用于填充业务逻辑选择该Layer需要执行的Handler的名称。下面是Divider具体实现的一个样例见github。 package mainimport (ghgroups/frameghgroupscontext ghgroups/frame/ghgroups_contextreflect )type ExampleDivider struct {frame.DividerBaseInterface }func NewExampleDivider() *ExampleDivider {return ExampleDivider{} }// /// // ConcreteInterface func (s *ExampleDivider) Name() string {return reflect.TypeOf(*s).Name() }// /// // DividerBaseInterface func (s *ExampleDivider) Select(context *ghgroupscontext.GhGroupsContext) string {return ExampleBHandler }应用 每个Layer都要通过配置文件来描述其组成。相较于HandlerGroup由于它不会执行所有的Handler而是要通过Divider来选择执行哪个Handler于是主要是新增Divider的配置项。 name: layer_a type: Layer divider: ExampleDivider handlers: - ExampleAHandler- ExampleBHandler具体执行的代码见github。我们看下运行结果 layer_aExampleDividerExampleAHandlerExampleBHandler run ExampleBHandler可以看到它只是执行了Divider选择的ExampleBHandler。 LayerCenter LayerCenter是一组串行执行的Layer的组合。 在使用LayerCenter时我们只要实现好每个Layer然后通过配置文件配置它们的关系即可。 type: LayerCenter name: layer_center layers: - layer_a- layer_b应用 具体代码和前面类似可以见github。 运行结果如下 layer_centerlayer_aExampleADividerExampleA1HandlerExampleA2Handlerlayer_bExampleBDividerExampleB1HandlerExampleB2Handler run ExampleA2Handler run ExampleB1Handler可以看到每个Layer选择了一个Handler执行。 源码见github。
http://www.hkea.cn/news/14494309/

相关文章:

  • 网站公共模板是什么意思网站搜索优化找哪家
  • 教你做面食的网站门户网站建设方式
  • 网站大致内容简述网站规划的一般步骤
  • 公司网站导航栏是什么怎样增加网站权重
  • 网站创意设计公司邮箱登录
  • 网站淘宝客一般怎么做网站怎么备案啊
  • 做文库网站怎么赚钱动漫设计专业就业前景
  • 无锡网站开发培训wordpress4.9标签404
  • 苏州大型网站设计公司扫码点餐小程序怎么制作
  • 成都网站设计公如何做京东优惠券网站
  • 人工智能和网站开发网站建设人工费一年多少钱
  • 网站运营外包公司客户推广渠道有哪些
  • 模板网站判定鲜花网站开发与设计
  • 广告投放效果评估seo做子网站
  • 做网站做地区好还是全国的好郑州网站建设技术精粹
  • 免费浏览的网站wordpress企业官网主题
  • 重庆网站设计制作网站手机wordpress写博客
  • 哪个网站可以做奖状做网站模板用什么框架
  • 大厂网站建设网站做多个语言有什么好处
  • 全国免费发布信息网站大全网站做维恩图
  • 网站推销话术wordpress个人博客绅士模板
  • 网站解析后怎么做钓鱼网页在线生成网站
  • 漳州网站建设网站运营站点和网页的关系
  • 东莞网站建设周期wordpress7.6
  • 张家口万全区建设网站中国遵义门户网站
  • 做信息类网站广州市官网网站建设
  • 易迈互联网站建设怎么样做电子杂志的网站
  • 网站分析表类似wordpress的应用
  • 地方门户网站盈利城乡与建设厅网站
  • 手机版网站版面设计怎么做网站建设以及网页设计需要会什么