SoFunction
Updated on 2025-03-05

Three development modes of golang projects developed using gin

Three development modes of golang project developed by gin

Gin is currently the most popular development framework of golang. This framework provides us with three environmental patterns:

  • DebugMode means that the gin mode is debug development mode
  • ReleaseMode means that gin mode is release production environment mode
  • TestMode means that gin mode is test test environment mode
const (
	// DebugMode indicates gin mode is debug.
	DebugMode = "debug"
	// ReleaseMode indicates gin mode is release.
	ReleaseMode = "release"
	// TestMode indicates gin mode is test.
	TestMode = "test"
)

If the gin development mode is not set, the default is degbug mode. If you need to switch mode, you can directly switch with the following code:

Set to development mode

()

Set to production environment mode

()

Set to test environment mode

()

If the project is to be released and launched, remember to switch to the production environment mode

If you do not add this line of code, when the service is started after packaging, the console will output:

[WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  ()

Prompt us to set environment variables or set them to production mode in code

The three modes of gin correspond to different scenarios. During our development and debugging process, we use DebugMode and debug mode. When the project is online, you must choose the ReleaseMode mode.

And you can use .TestMode mode when testing

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.