How to run a golang program on https

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"github.com/gorilla/mux"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	r := mux.NewRouter()

	httpsMux := http.NewServeMux()

	httpsMux.Handle("/", http.HandlerFunc(infoTeam))

	go http.ListenAndServeTLS(":8488", "cert.pem",
		"key.pem", httpsMux)

	http.Handle("/", r)

	fmt.Println("Main Page")
}

//--------------------------------------------------------------------------------------------

func infoTeam(rw http.ResponseWriter, r *http.Request) {

	fmt.Println("Main Page")
	rw.Header().Set(" Server in Golang")
	rw.Write([]byte("Service (Golang Server)\nTeam Members:\n Agha Assad\n"))
}


Please have a look at the sticky thread, that helps enormously to better be able to help you:

What exactly is your question / what problem do you want to solve?
Apart from guessing that your code example is incomplete, I can’t see anything particular that the go compiler wouldn’t tell you already.

If your request is for detailed feedback on your code, I can give that, but I’d suggest trying to improve it yourself first, based on the compiler errors, that’s good practice :slight_smile:

3 Likes