In the last section, we have built the actual combat project framework and imported the static resource files needed for the development of the actual combat project. In this section, we will show you how to initialize and run the project through the relevant configuration.
Conf Configuration file Reads configuration information
As mentioned earlier, the config.json configuration file is used to configure the project. In this section, we will do a simple configuration first. There are two parts: config.json and the method to read the configuration. As follows:
{
"app_name": "CmsProject"."port": 9000,
"static_path": "/manage/static"."mode": "dev"
}Copy the code
Accordingly, provide an AppConfig structure and an InitConfig method to read configuration data:
type AppConfig struct {
AppName string `json:"app_name"`
Port int
StaticPath string `json:"static_path"`
Mode string `json:"mode"`}Copy the code
Static resource path configuration and template file configuration
-
Static resource path configuration: In the Iris framework, there is a special method for developers to set the static resource path, because only the static resource path can be directly accessed in the browser, otherwise it is not accessible. Iris sets the static resource path as shown in the following example:
app.StaticWeb("/manage/static"."./static")Copy the code
-
Template file configuration: Iris framework also supports us to register template files, as shown in the following case:
app.RegisterView(iris.HTML("./static".".html"))Copy the code
The project is initialized to run
After completing the project architecture and the above project configuration, we can start our project and see the effect of the project. Now that the project creation and infrastructure are in place, we will focus on the project functionality.