Gocloudcoder replies to books to receive learning materials, including Linux, Golang, Java, JS, operating systems, computer networks, programming experience, algorithms and data structures, etc.

Today, I went to the teacher to talk about the development project. The teacher simply and rudely gave me a pile of information, a development board, a switch, a network line, and said to go back and look at the information! Ah this, big man speech is so simple and rough?

So I began to explore the road, of course, the only reference is the files in this folder.

The router board was developed using the Linux kernel, and the distribution is called OpenWRt.

First, in order to connect to the terminal on the board, you need to configure the network mode. First I chose a USB cable or wired connection to the OpenWRT terminal. Classic LS rage. But since this is a router device, I should configure wifi mode connection which is a wireless connection, so I looked at this document. Finally, one end of the network cable was inserted into the WAN interface of the development board and the other end into the LAN interface of the router in our dormitory. Then MY computer is connected to wifi, and I can successfully connect to the Internet. I think this principle is that the router in the dormitory will forward the traffic to the development board, and THEN I will access the traffic from the wifi on the development board to achieve access to the Internet.

The teacher said that you should not connect wifi in public places as much as possible, because it is extremely insecure. If you access insecure services (such as HTTP but not HTTPS), your personal information will be exposed. Today, I really understand that I can provide wifi to other people through this development board. When other people are connected to this WIFI, I can get information by capturing packets. So we try not to connect wifi in public places, to prevent some people from stealing information to cause losses.

Being a Gopher, I certainly had to try out how to run the go program on this development board! If you can run the GO code successfully, there’s a lot more to do! Seems to be getting interesting!

Through some Linux commands (uname -a), I learned that the CPU architecture of the development board is MIPS, which is widely used in electronics, networking devices, personal entertainment devices, and business devices. We know that the CPU architecture is generally Intel, AMD, ARM, this is also a supplement to the knowledge!

We don’t install the Go compiler on the development board for the following reasons:

  • Generally, this development board has less memory and disk space.
  • Various software dependency packages are difficult to find, easy to cause problems

So we should use cross-compilation to compile binaries that run directly on the MIPS architecture. We cross-compile the GO code on the Windows platform to produce binaries that run directly on MIPS.

Write the classic Hello World code

package main
import (
	"fmt"
)
func main(a) {
    fmt.Println("hello")}Copy the code

Then we cross-compiled and had to compliment go on how well it supported on all platforms!

GOOS=linux GOARCH=mipsle go build -ldflags "-s -w" hello.go
Copy the code

The next step is to consider how to transfer the compiled binary hello to the development board.

I used the SCP command.

First grant executable permissions with chmod +x Hello, and then execute the binary.

Successful execution! Very nice!

I then tried to run the HTTP service and had no problem, so the rest was easy! Interesting things, wait and see ha ha.