I suspect you may have misunderstood what a "CA Certificate" is.  It's not 
the Certificate Signing Request (CSR) that you created for your own public 
key.  It's the public key of the certificate authority which signed the 
server's certificate (i.e. google.com).

However, since google.com is signed by one of the standard public CAs, you 
don't need to specify a CA certificate at all, and it will use your 
system's default set of root CAs.

The following variation of your code works for me.  I removed the client 
cert/key as well, since google doesn't require you to present a client cert.

package main

import (
  "fmt"
  //log "github.com/sirupsen/logrus"
  "github.com/valyala/fasthttp"
  "crypto/tls"
  //"crypto/x509"
  //"io/ioutil"
)

func req(method string, url string, data []byte) (int, []byte) {
    // Setup HTTPS client
    tlsConfig := &tls.Config{
      Certificates: []tls.Certificate{},
    }

  req := fasthttp.AcquireRequest()
  req.SetRequestURI(url)
  req.Header.SetMethod(method)
  req.SetBody(data)
  resp := fasthttp.AcquireResponse()

  client := &fasthttp.Client{
    TLSConfig: tlsConfig,
  }
  client.Do(req, resp)
  statusCode := resp.StatusCode()
  body := resp.Body()
  return statusCode, body
}

func main(){
  a, b := req("GET", "https://google.com";, nil)

  fmt.Printf(string(b))
  fmt.Println(a)

}

The result:

<HTML><HEAD><meta http-equiv="content-type" 
content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/";>here</A>.
</BODY></HTML>
301

(and if you change https://google.com to https://www.google.com then you 
get the search page)

-- 
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/ac90bbe8-9546-4ed7-b2f1-643d07d24abco%40googlegroups.com.

Reply via email to