Dotweb frame Tour [II]-Common object-app (dotweb)

Source: Internet
Author: User

Dotweb belongs to a web framework that wants to help developers quickly build Web applications, improve development efficiency, and reduce unnecessary code bloat through framework behavior.

The dotweb contains several common objects:

    • App (Dotweb) app container that provides the necessary container class functionality for Web request processing.
    • Httpserver A service module that is used to truly handle Web requests.
    • HttpContext is used to provide quick processing and unique access to request information and response information in a single request processing.
    • The Response is used to send output from the server to the user.
    • Request is used to obtain information from the user.
    • Session is used to store information about a connection session, or to modify related settings. Currently supports storage of native memory with Redis distributed.

At the beginning of this chapter, this series of objects will be described in common scenarios.

The App object, defined as Dotweb in Dotweb, is primarily responsible for providing the necessary container class functionality for Web request processing, such as starting web snooping, configuring initialization, setting the operating mode, setting up the log, setting up the cache, and also taking on a range of shortcut function portals.

Main properties:

Property Describe Default value
Httpserver
App-hosted Webserver objects
Newhttpserver ()
Config
Global configuration information, mapping dotweb.conf
Config. Newconfig ()
Middlewares
App-Level middleware collections
Make ([]middleware, 0)
Exceptionhandler
Custom Handling Exception methods
Defaulthttperrorhandler ()
Notfoundhandler
Custom 404 Request Processing Method
Defaultnotfoundhandler ()
Methodnotallowedhandler
Custom 405 Request Processing method
Defaultmethodnotallowedhandler ()
AppContext
App-level global memory kv storage
Newitemcontext ()
Offlineserver
Maintenance webserver
Newofflineserver ()

Main methods :

Method Describe
Start ()
Start the web port monitoring according to the configuration, and if an error occurs, return the specific Error object
Listenandserve (Addr string)
Specify host:port to initiate web port monitoring based on configuration
Use (M ... Middleware)
Register middleware, all request sharing
Setdevelopmentmode () \setproductionmode ()
Set development mode \ production mode
Cache ()
Provides a global memory cache entry
Userequestlog ()
Enable the base request log middleware
Setpprofconfig ()
Setting Pprof Listening port information
Setlogger (log logger. Applog)
Set up custom log plug-ins

General Usage Code:

Func Main () {//Initialize AppApp: =Dotweb. New ()//set the Dotserver log directory//if not set, default is not enabled and defaults to the current directoryApp. Setenabledlog (true)    //turn on development modeapp. Setdevelopmentmode ()//set up RoutesInitroute (app. Httpserver)//Custom 404 Outputapp. Setnotfoundhandle (func (ctx dotweb). Context) {ctx. Response (). Write (http. Statusnotfound, []byte("is ' t app ' s not found!"))    })    //Start the Monitoring serviceApp. Setpprofconfig (true,8081)    //Global ContainerApp. Appcontext.set ("app","Dotweb")    //Start ServicePORT: =8080FMT. Println ("Dotweb. StartServer ="+StrConv. Itoa (port)) Err:=app. StartServer (port) fmt. Println ("Dotweb. StartServer error =", err)}

More code can refer to Https://github.com/devfeel/dotweb-example

Welcome everyone to join our Go language QQ Group: 193409346

Dotweb frame Tour [II]-Common object-app (dotweb)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.