Run Template And Go Back to main

HEy Guys.
I need a help.
Im executing a program that i need to go to a template, and on this template i have a form with a textbox and a submit button.
After that happen, i have to go back to main and execute the next line.
But, my aplication execute the template and dont go back to main.
How can i Fix that?
Thx :slight_smile:

My main func : `func main() {
http.HandleFunc("/", index)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
logger.Println(“Erro ao iniciar a aplicacao erro : %s”, err)
}
cmd := exec.Command(“bash”, Script)

}

my Template index.html is :

Mensagem a ser Enviada ao servidor

Mensagem :

My index Func is :
func index(w http.ResponseWriter, r *http.Request) {
fmt.Println(“method:”, r.Method) //get request method
if r.Method == “GET” {
t, _ := template.ParseFiles(“index.html”)
t.Execute(w, nil)
return
} else {
r.ParseForm()
mensagem := r.FormValue(“mensagem”)
fmt.Fprintf(w, “Mensagem a ser enviada para o Servidor= %s \n”, mensagem)
f, err := os.Create("…/…/CamadaFisica/cliente/Dado.txt")
//main.logger.Println(“Criando a PDU da Camada De Aplicacao”)
if err != nil {
fmt.Println(err)
return
}

	l, err := f.WriteString(mensagem)
	if err != nil {
		fmt.Println(err)
		fmt.Println(l)
		f.Close()
		return
	}
	f.Close()
	return
}
return

}
`

2 Likes

Hi Marcos, Can you share the code with https://play.golang.org or https://pastebin.com/ ?

3 Likes

Hi Anar, Really thank for ur attention !
I solved it yesterday! I really appreciate u being available to help.
Well, Ive put the line of the comand inside of the index func.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.