五步让你成为GO 语言高手

2020-01-28 11:40:04王冬梅

            log.Printf("warning: compile the package to analyze the error")
            src = buf.Bytes()
        }
 
        output := strings.ToLower(typeName + *outputSuffix + ".go")
        outputPath := filepath.Join(dir, output)
        if err := ioutil.WriteFile(outputPath, src, 0644); err != nil {
            log.Fatalf("writing output: %s", err)
        }
    }}

一段互动的片段演示了如何编写jsonenums命令。

OpenGL

许多人使用Go作web服务,但是你知道你也可以用Go写出很cool的图形应用吗?查看Go在OpenGL中的捆绑。



func main() {
    glfw.SetErrorCallback(errorCallback)
 
    if !glfw.Init() {
        panic("Can't init glfw!")
    }
    defer glfw.Terminate()
 
    window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
    if err != nil {
        panic(err)
    }
 
    window.MakeContextCurrent()
 
    glfw.SwapInterval(1)
 
    gl.Init()
 
    if err := initScene(); err != nil {
        fmt.Fprintf(os.Stderr, "init: %sn", err)
        return
    }
    defer destroyScene()
 
    for !window.ShouldClose() {
        drawScene()
        window.SwapBuffers()
        glfw.PollEvents()
    }}

交互式的片段正说明Go的OpenGL捆绑能制作Gopher cube。点击函数或方法名去探索。

黑客马拉松和挑战

你也可以观看挑战和黑客马拉松,类似Gopher Gala和Go Challenge。在过去,来自世界各地的程序员一起挑战一些真实的酷项目,你可以从中获取灵感。

第三阶段: 老手

作为一个老手,这意味着你可以解决很多Go语言中你关心的问题。新的需要解决的问题会带来新的疑问,经过试错,你学会了在这门语言中什么是可以做的,什么是不能做的。此时,你已经对这门语言的习惯和模式有了一个坚实的理解。你可以非常高效地工作,写出可读,文档完善,可维护的代码。