I want to create unique dynamic subdomains for every users when they create new accounts, but without any frameworks.
I tried this:
<code>func home (w http.ResponseWriter, r *http.Request){
//The Host that the user queried.
host := r.URL.Host
host = strings.TrimSpace(host)
//Figure out if a subdomain exists in the host given.
host_parts := strings.Split(host, ".")
if len(host_parts) > 2 {
//The subdomain exists, we store it as the first element
//in a new array
subdomain := []string{host_parts[0]}
}
`// And I look for a username with this subdomain name and display it with the right template
}
</code>
<code>func home (w http.ResponseWriter, r *http.Request){
//The Host that the user queried.
host := r.URL.Host
host = strings.TrimSpace(host)
//Figure out if a subdomain exists in the host given.
host_parts := strings.Split(host, ".")
if len(host_parts) > 2 {
//The subdomain exists, we store it as the first element
//in a new array
subdomain := []string{host_parts[0]}
}
`// And I look for a username with this subdomain name and display it with the right template
}
</code>
func home (w http.ResponseWriter, r *http.Request){
//The Host that the user queried.
host := r.URL.Host
host = strings.TrimSpace(host)
//Figure out if a subdomain exists in the host given.
host_parts := strings.Split(host, ".")
if len(host_parts) > 2 {
//The subdomain exists, we store it as the first element
//in a new array
subdomain := []string{host_parts[0]}
}
`// And I look for a username with this subdomain name and display it with the right template
}
But I do not know this is a right way to do this?!
New contributor
Alex Wat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.