1

I am trying to set up a REST endpoint in Go in the Eclipse-Che workspace

My code is shown below:

package main

import (
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(http.ResponseWriter, *http.Request) {
        log.Println("Hello world1")
    })
    http.HandleFunc("/goodbye", func(http.ResponseWriter, *http.Request) {
        log.Println("Goodbye world")
    })
    http.ListenAndServe(":8085", nil)
}

On running my go code, I'm getting the following output.

bash-4.4 /projects/src/github.com/golang $ curl -V 10.130.54.6/8084
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2u zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 
bash-4.4 /projects/src/github.com/golang $ curl -V http://10.130.54.6/8084
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.2u zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 
Ayman Arif
  • 1,456
  • 3
  • 16
  • 40

1 Answers1

3

There are two problem with your request:

  • You aren not sending a request to your webserver (IP/NUMBER describe a subnet) .
  • You are using -V instead of -v (that show the version of the cURL tool).

Try with:

curl -v 127.0.0.1:8085
#curl -v 0.0.0.0:8085 will also work

This because you are running the software in your machine, binding the service at port 8085

If your firewall is open, you can query the service from another machine in the same network using:

curl -v 10.130.54.6:8084

You can retrieve your internal ip using ifconfig, and checking which device (eth0, lo ecc) are you using for access to internet.

alessiosavi
  • 2,753
  • 2
  • 19
  • 38