---
title: "Go Web 开发（一）"
author: "ihuashao"
date: "2011-03-10T00:52:00Z"
tags: []
slug: "go-web"
draft: false
lastmod: "2011-03-10T00:52:00Z"
id: 955751
url: "https://jishudaima.iteye.com/blog/955751"
---

## 目的

了解 Go 开发 Web 应用的基本原理。

## 效果

![](http://88250.b3log.org/datastore-file-access.do?oId=1299689200847)

![](http://88250.b3log.org/datastore-file-access.do?oId=1299689211715)

## 代码

> package main
> 
> import (  
> "fmt"  
> "http"  
> )
> 
> type User struct {  
> Name string  
> }
> 
> func Register(w http.ResponseWriter, r \*http.Request) {  
> if "GET" == r.Method {  
> fmt.Fprintln(w, "
> 
> # Register
> 
> " +  
> "
> 
> " +  
> " User Name: " +  
> "
> 
> ")  
> return  
> }
> 
> user := &User{r.FormValue("userName")}  
> fmt.Fprintln(w, "Hello ", user.Name)  
> }
> 
> func main() {  
> http.HandleFunc("/", Register)  
> http.ListenAndServe(":8080", nil)  
> }

## 总结

- 相比 Java Web 开发，简洁不少（语法、配置）
- 调试不方便，需要重编译、链接

## 下一步

- 模板入门
- 数据持久化

本文是使用 [B3log Solo](http://b3log-solo.googlecode.com/) 从 [简约设计の艺术](http://88250.b3log.org:80) 进行同步发布的

原文地址：[http://88250.b3log.org/go-web-1.html](http://88250.b3log.org/go-web-1.html)