PHP To Go transition notes (final)

  golang, php



As a PHP programmer, I feel honored. However, in the changing times, one must have sufficient knowledge to survive.

Let’s start with Go linguistics.

I hope you can have a basic understanding of Go after reading this article. This series of articles describes the way I learned Go language. The comparison between PHP code and Go code is used to distinguish and understand.

This is the last chapter of the transition notebook. I can’t write it down any more. I need to read it in detail. This chapter compares PHP and Golang in actual combat.

Here, Laravel and Beego (MVC Framework Developed Based on Go) are used to demonstrate



//Direct installation via composer is simple and easy to use
 composer global require "laravel/installer"
 //Create a project
 laravel new blog


// go has its own package management
 go get
 //Creating a project is also very simple
 bee api blog

directory structure


// laravel's structure will not be described here.
 | - app
 | - bootstrap
 | - config
 | - database
 | - public
 | - resources
 | - routes
 | - storage
 | - tests
 | - vendor


//Obviously, beego is not over-designed like laravel (although over-design does not refer to directories,
 //But look at the catalog and you will know that beego really doesn't have too many things)
 ├── conf
 │   └── app.conf
 ├── controllers
 │   └── object.go
 │   └── user.go
 ├── docs
 │   └── doc.go
 ├── main.go
 ├── models
 │   └── object.go
 │   └── user.go
 ├── routers
 │   └── router.go
 └── tests
 └── default_test.go



Route::get('/user', 'UserController@index');


//Similar to laravel
 //For the sake of unification, there are only the following methods for routing directly to bind controllers.
 // beego also provides annotation methods. See for details



<?  php
 namespace App;
 use Illuminate\Database\Eloquent\Model;
 class User extends Model
 * Data table associated with the model.
 * @var string
 protected $table = 'user';


// Beego uses the structure name as the table name, and all fields of orm operation must be declared in advance
 package models
 import (
 type User struct {
 Id       int    `json:"id"`
 Tel      string `json:"tel"`
 Password string `json:"password"`
 Status   string `json:"status"`
 func init() {



<?  php
 namespace App\Http\Controllers;
 use App\User;
 use App\Http\Controllers\Controller;
 class UserController extends Controller
 * Displays the profile for a given user
 * @param  int  $id
 * @return Response
 public function index($id)
 return view('user.profile', ['user' => User::findOrFail($id)]);


package controllers
 import (
 //This is equivalent to inheriting the parent beegoController
 type MemberController struct {
 func (c *CityController) Index() {
 var results []orm.Params
 c.Data["json"] = results


I have been studying Go for more than a month. Writing such articles has also met with a lot of doubts. As a notebook, it is published only to give friends who want to learn other languages an understanding of the new language, not to compare its differences. But look for grammatical similarities.

Language is only a tool. I hope that PHP engineers will not only use PHP. This year, they have seen many articles about the future of PHP programmers, but have never proposed to learn other languages.

Don’t circle yourself in a field, don’t be a frog in the bottom of a well.

Thank you

Thank you for seeing here. I hope this article can help you. Thank you