Go get Started

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Learning Materials http://docs.plhwin.com/gopl-zh/

A Development Environment Construction

0x1 Installation Gosdk

Windows system download Https://storage.googleapis.com/golang/go1.8.3.windows-amd64.msi need to flip the wall.

0x2 Local environment variable with

GOBIN=C:\Go\bin          GOROOT=C:\Go          GOPATH=C:\GoWrokspaces      PATH= ;C:\Go\bin;C:\GoWorkspaces\bin    

In the Goworkspaces directory, you need to create a new directory of three files, respectively, src,bin,pkg.

0x3 Installing the Development IDE

JetBrains Goglang https://www.jetbrains.com/go/
Edit Go App Run environment


Editconfiguration
Set up the app to run the main file

Run_file.

B developing basic syntax

The and of the function parameters of 0x1 "值传递""引用传递"

type Emplyee struct {    Name   string    Age    int    Status string    Wallet int}func healthCheckup(emplyee Emplyee) {    emplyee.Status = "Do Health Checkup"    emplyee.Wallet=emplyee.Wallet-50    fmt.Printf("%s 正在做体检 花费了50 还剩余额%d\n",emplyee.Name,emplyee.Wallet)}func financeRoom(emplyee *Emplyee)  {    emplyee.Wallet=emplyee.Wallet+1000;    fmt.Printf("%s 领取了工资 领取了1000 还剩余额%d\n",emplyee.Name,emplyee.Wallet)}func main() {    var emp = Emplyee{Name: "larry", Age: 32, Status: "working",Wallet:100}    fmt.Printf("员工做体检前 %v\n",emp)    healthCheckup(emp)    fmt.Printf("员工做体检后 %v\n",emp)    fmt.Printf("员工领工资前 %v\n",emp)    financeRoom(&emp)    fmt.Printf("员工领工资后 %v\n",emp)}

Output

员工做体检前 {larry 32 working 100}      larry 正在做体检 花费了50 还剩余额50      员工做体检后 {larry 32 working 100}      员工领工资前 {larry 32 working 100}      larry 领取了工资 领取了1000 还剩余额1100      员工领工资后 {larry 32 working 1100}      

0x2 interface type definition and implementation class

// 定义Service接口,包含两个方法.type Service interface {    Sum(a, b int) (int, error)    Concat(a, b string) (string, error)}// 返回实现Service接口的 basicServicefunc NewBasicService() Service {    return basicService{}}//定义一个Service接口的实现结构体type basicService struct{}// 实现Service接口的Sum方法.   func (s basicService) Sum(a, b int) (int, error) {   ...}// 实现Service接口的Concat方法.func (s basicService) Concat(a, b string) (string, error) {   ...   }

0x3 Anonymous functions

//greetingToWord 的参数为函数类型,参数名称_fGreeting func greetingToWord(_fGreeting func(whom string) string) string{    word:=" word "    return _fGreeting(word)}func greeting(whom string)string  {    return "1 hello "+ whom}func main() {    //传递greeting 函数    someGreeting := greetingToWord(greeting)    fmt.Println(someGreeting)    //局部实现匿名函数    someGreeting =greetingToWord(func(whom string) string {        return "2 hello "+whom    })    fmt.Println(someGreeting)    }

Output:

1 hello  word      2 hello  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.