Added http-server /headers example
This commit is contained in:
parent
15d8fe75b8
commit
8006140dd4
@ -4,3 +4,9 @@ $ go run http-servers.go &
|
||||
# Access the `/hello` route.
|
||||
$ curl localhost:8090/hello
|
||||
hello
|
||||
|
||||
|
||||
# Access the `/headers` route.
|
||||
$ curl localhost:8090/headers
|
||||
Accept: */*
|
||||
User-Agent: curl/8.1.2
|
||||
|
17
public/http-server
generated
17
public/http-server
generated
@ -168,13 +168,26 @@ router we’ve just set up.</p>
|
||||
<p>Access the <code>/hello</code> route.</p>
|
||||
|
||||
</td>
|
||||
<td class="code">
|
||||
<td class="code leading">
|
||||
|
||||
<pre class="chroma"><code><span class="line"><span class="cl"><span class="gp">$</span> curl localhost:8090/hello
|
||||
</span></span><span class="line"><span class="cl"><span class="go">hello</span></span></span></code></pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="docs">
|
||||
<p>Access the <code>/headers</code> route.</p>
|
||||
|
||||
</td>
|
||||
<td class="code">
|
||||
|
||||
<pre class="chroma"><code><span class="line"><span class="cl"><span class="gp">$</span> curl localhost:8090/headers
|
||||
</span></span><span class="line"><span class="cl"><span class="go">Accept: */*
|
||||
</span></span></span><span class="line"><span class="cl"><span class="go">User-Agent: curl/8.1.2</span></span></span></code></pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
@ -190,7 +203,7 @@ router we’ve just set up.</p>
|
||||
</div>
|
||||
<script>
|
||||
var codeLines = [];
|
||||
codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"net/http\"\u000A)\u000A');codeLines.push('func hello(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' fmt.Fprintf(w, \"hello\\n\")\u000A}\u000A');codeLines.push('func headers(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' for name, headers :\u003D range req.Header {\u000A for _, h :\u003D range headers {\u000A fmt.Fprintf(w, \"%v: %v\\n\", name, h)\u000A }\u000A }\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' http.HandleFunc(\"/hello\", hello)\u000A http.HandleFunc(\"/headers\", headers)\u000A');codeLines.push(' http.ListenAndServe(\":8090\", nil)\u000A}\u000A');codeLines.push('');codeLines.push('');
|
||||
codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"net/http\"\u000A)\u000A');codeLines.push('func hello(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' fmt.Fprintf(w, \"hello\\n\")\u000A}\u000A');codeLines.push('func headers(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' for name, headers :\u003D range req.Header {\u000A for _, h :\u003D range headers {\u000A fmt.Fprintf(w, \"%v: %v\\n\", name, h)\u000A }\u000A }\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' http.HandleFunc(\"/hello\", hello)\u000A http.HandleFunc(\"/headers\", headers)\u000A');codeLines.push(' http.ListenAndServe(\":8090\", nil)\u000A}\u000A');codeLines.push('');codeLines.push('');codeLines.push('');
|
||||
</script>
|
||||
<script src="site.js" async></script>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user