htm code like google page
Sure! Here is an example of how you can create an HTML page that resembles the Google homepage using the Go programming language:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", handleRequest)
http.ListenAndServe(":8080", nil)
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
html := `
<!DOCTYPE html>
<html>
<head>
<title>Google</title>
</head>
<body>
<div style="text-align: center; margin-top: 200px;">
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="Google Logo" width="272" height="92">
<br>
<input type="text" style="width: 300px; height: 30px; font-size: 16px;">
<br>
<button style="background-color: #4285F4; color: white; font-size: 16px; padding: 10px 20px; border: none; border-radius: 4px;">Search</button>
</div>
</body>
</html>
`
fmt.Fprint(w, html)
}
Explanation:
- The
http
package is imported to handle the server and routing functionality. - The
main
function sets up a simple HTTP server usinghttp.HandleFunc
to handle requests andhttp.ListenAndServe
to start the server on port 8080. - The
handleRequest
function is called whenever a request is made to the server. It takes in ahttp.ResponseWriter
and ahttp.Request
as parameters. - The
html
variable contains the HTML code that represents the Google homepage. - The
fmt.Fprint
function is used to write the HTML code to thehttp.ResponseWriter
, which sends the HTML response back to the client.
In summary, this Go code sets up a basic HTTP server that responds to any request with an HTML page resembling the Google homepage.