hi john,
other than php, go programs are compiled to an executable that can then
be run. you can not put go files in a folder and expect that to work.
you probably followed a tutorial to set up a go http server with a
simple route. the reason you get that idea that you can use file names
comes probably from the simple router mux of the http package that does
check only the prefix of the request path for you.
try just http://localhost:8080 and you probably see the same form.
to have one program that includes the code of both files they need to be
part of the same package and must be compiled together.
from your description i gather that you probably ran "go run main2.go"
witch will only compile that one file into a program and run it.
instead you need to either list all the files of your main package
"go run main2.go main.go". or: go run is meant a convenience for mostly
single file programs, so instead most people use "go install" or "go
build" and execute the resulting program.
if both files are compiled into the same program they can have only one
main function. where you need to setup the http server and its routes.
there you can register the http handlers with path prefixes that you can
call from your html form.
hope that helps
if you need more detailed help please include the commands you ran and
a links to the code pasted somewhere; preferable the go playground.
On 8/4/22 21:06, John Dutcher wrote:
I have a tiny server program in Go language (main2.go) running and
'listening' on port 8080 in a Windows command prompt session. While
running I point a browser to http://localhost:8080/main2.go and main2.go
executes and places a small html form into the browser window to fill
and submit. If the form ACTION has any requested target for some other
Go program or HTML element resident in the same Windows folder as
main2.go, the element request is ignored .... ONLY 'main2.go' gets
triggered to execute instead in response to the POST request 'submitted'.
I have tried all variations I can think of in the POST ACTION URL format
to get the POST to run an element in the Windows folder called 'main.go'
(instead of main2.go):
ACTION examples:
http://localhost:8080/main.go
localhost:8080/main.go
/main.go
../main.go
./main.go
BUT, if I load the ACTION URL with something like
'https://www.google.com' it brings the home page for Google right into
the browser window no problem.
Why can it not run main.go, which again, resides in the same Windows
folder as main2.go which is the Go program running as the swerver ?
--
You received this message because you are subscribed to the Google
Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to golang-nuts+unsubscr...@googlegroups.com
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/8ae6812d-a551-429d-ab6b-5215063a60a2n%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/8ae6812d-a551-429d-ab6b-5215063a60a2n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/4e724e44-84b9-8d4b-a330-ae7edd4e1876%40mb0.org.