[Internal] Web Server Initialization

Important Notes

This document describes what is the initialization flow of Gogs web server (./gogs web).

Entry point

The entry point for the web server is the function cmd/web.go:runWeb.

The function runWeb does several things (in order):

  1. Check custom config file path argument
  2. Initialize modules
  3. Check template and dependencies versions
  4. Resigter routes
  5. Check custom listen port argument
  6. Start web server

Check command line arguments

There are two command line arguments checked in the initialization of web server:

Initilize modules

The module initialization of web server is encapsulated in the function routers/install.go:GlobalInit.

Modules to be initialized:

  • setting: application settings
  • highlight: code highlighting helpers
  • models: database related backend operations
  • mailer: email sending helpers
  • cron: cron tasks
  • ssh: built-in SSH server
  • markdown: Markdown rendering helpers

Some background processes are initialized at this time:

If this is the first time Gogs starts (user has not yet finish installation), the initialization of some modules and background processes will be skipped.

:speech_balloon: Please leave comments if you have any questions or concerns about this post.