github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/web/examples/params.go (about)

     1  // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build ingore
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/chai2010/gopkg/web"
    13  )
    14  
    15  func index() string {
    16  	return page
    17  }
    18  
    19  func process(ctx *web.Context) string {
    20  	return fmt.Sprintf("%v\n", ctx.Params)
    21  }
    22  
    23  func main() {
    24  	web.Get("/", index)
    25  	web.Post("/process", process)
    26  	web.Run("0.0.0.0:9999")
    27  }
    28  
    29  const page = `
    30  <html>
    31  	<head>
    32  		<title>Multipart Test</title>
    33  	</head>
    34  	<body>
    35  		<form action="/process" method="POST">
    36  			<label for="a"> Please write some text </label>
    37  			<input id="a" type="text" name="a"/>
    38  			<br>
    39  
    40  			<label for="b"> Please write some more text </label>
    41  			<input id="b" type="text" name="b"/>
    42  			<br>
    43  
    44  			<label for="c"> Please write a number </label>
    45  			<input id="c" type="text" name="c"/>
    46  			<br>
    47  
    48  			<label for="d"> Please write another number </label>
    49  			<input id="d" type="text" name="d"/>
    50  			<br>
    51  
    52  			<input type="submit" name="Submit" value="Submit"/>
    53  		</form>
    54  	</body>
    55  </html>
    56  `