github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/form/web/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/micro/go-micro/v2/web"
     8  )
     9  
    10  func index(w http.ResponseWriter, r *http.Request) {
    11  	fmt.Fprint(w, `<html>
    12  <body>
    13  <h1>This is a regular form</h1>
    14  <form action="http://localhost:8080/form/submit" method="POST">
    15  <input type="text" id="thing" name="thing" />
    16  <button>submit</button>
    17  </form>
    18  <h1>This is a multipart form</h1>
    19  <form action="http://localhost:8080/form/multipart" method="POST" enctype="multipart/form-data">
    20  <input type="text" id="thing" name="thing" />
    21  <button>submit</button>
    22  </form>
    23  </body>
    24  </html>
    25  `)
    26  }
    27  
    28  func main() {
    29  	service := web.NewService(
    30  		web.Name("go.micro.web.form"),
    31  	)
    32  	service.Init()
    33  	service.HandleFunc("/", index)
    34  	service.Run()
    35  }