GoFrame introduction and installation

  • A. GoFrame profile

    • 1. An overview
    • 2. The characteristics of
    • 3. The architecture
  • 2. Install

    • 1. Terminal installation
    • 2. Go mod installation
  • 3. Hello World

GoFrame is a fully functional framework. The first part of the study notes focuses on Web services development, documenting what you learn, what you think, and what you get.

To do a good job, he must sharpen his tools. This article focuses on what a GoFrame framework is and how to install it.

A. GoFrame profile

1. An overview

GF(Go Frame) is a modular, high-performance, production-grade Go basic development framework. It has realized relatively perfect infrastructure construction and development tool chain, and provided common basic development modules, such as: Caches, logs, queues, arrays, collections, containers, timers, command lines, memory locks, object pools, configuration management, resource management, data validation, data encoding, scheduled tasks, database ORM, TCP/UDP components, process management/communication, and more. Router, Cookie, Session, Middleware, service registry, template engine, hot restart, hot update, domain binding, TLS/HTTPS, Rewrite, etc.

2. The characteristics of

  • Modular, loose coupling design;
  • Modules rich, out of the box;
  • Easy to use, easy to maintain;
  • High code quality, high unit test coverage;
  • Active community, Daniel humble low-key good temper;
  • Detailed development documents and examples;
  • Perfect local Chinese culture support; Designed for team and enterprise use;

3. The architecture

Architecture diagram taken fromThe official website:

2. Install

1. Terminal installation

Enter the following command on the terminal:

go get -u -v github.com/gogf/gf
Copy the code

2. Go mod installation

Add the following command to the go.mod file:

require github.com/gogf/gf latest
Copy the code

The practice is shown below (Goland) :



The contents in the figure from top to bottom are my project name, GoFrame dependency management and version number, and Go language version respectively.

3. Hello World

Write the first GoFrame demo to verify the success of the installation and experience the initial use of GF. The code is as follows:

package main

import (
 "github.com/gogf/gf/frame/g"
 "github.com/gogf/gf/net/ghttp"
)  func main(a) {  s := g.Server()   s.BindHandler("/".func(r *ghttp.Request) {  r.Response.Write("Hello World!")  })   s.Run() // The default port is 80 } Copy the code

The main function of this code is to print a string to the page, saying: Hello World!

We’ll go over the details one by one.

When started, the Goland console outputs:



Open the browser, enter localhost for the url, and the page access result:



So here we areGoFrameFramework and its installation, and wrote the first demo.GoFrameThere is still a wider world to explore. Let us embark on this journey, forge ahead and stay true to our original aspiration.