Last active
July 12, 2020 16:04
-
-
Save kenng/691fa4c1f8e93b24c5afd37f61f751f5 to your computer and use it in GitHub Desktop.
Revisions
-
kenng revised this gist
Jul 12, 2020 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,12 @@ import ( "os" ) // usage: // with default parameter // <program> // // to specify different path and filename // <program> -d <ssl-directory> -c <cert-crt-filename> -k <cert-key-filename> func main() { homeDir, err := os.UserHomeDir() if err != nil { -
kenng revised this gist
Jul 12, 2020 . 1 changed file with 22 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,48 +1,42 @@ package main import ( "flag" "fmt" "log" "net/http" "os" ) // usage: <program> <ssl-directory> <cert-crt-filename> <cert-key-filename> func main() { homeDir, err := os.UserHomeDir() if err != nil { log.Fatal("error in getting home directory") } sslCertDirArg := flag.String("d", homeDir+"/ssl-local-cert", "the directory of SSL cert") sslCrtNameArg := flag.String("c", "test.iw.com.pem", "the filename of SSL cert") sslKeyNameArg := flag.String("k", "test.iw.com-key.pem", "the filename of SSL key") flag.Parse() if string((*sslCrtNameArg)[0]) != "/" { *sslCrtNameArg = "/" + *sslCrtNameArg } if string((*sslKeyNameArg)[0]) != "/" { *sslKeyNameArg = "/" + *sslKeyNameArg } sslCertCrtPath := *sslCertDirArg + *sslCrtNameArg sslCertKeyPath := *sslCertDirArg + *sslKeyNameArg fmt.Println(sslCertCrtPath) fmt.Println(sslCertKeyPath) // create file server handler serving current directory fs := http.FileServer(http.Dir(".")) // start HTTP server with `fs` as the default handler fmt.Println("server run with :9000 and :443") log.Fatal(http.ListenAndServeTLS(":443", sslCertCrtPath, sslCertKeyPath, fs)) log.Fatal(http.ListenAndServe(":9000", fs)) } -
kenng revised this gist
Jul 12, 2020 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,13 +10,10 @@ import ( // usage: <program> <ssl-directory> <cert-crt-filename> <cert-key-filename> func main() { sslCertCrtName, sslCertKeyName := setCertPath() // create file server handler serving current directory fs := http.FileServer(http.Dir(".")) // start HTTP server with `fs` as the default handler fmt.Println("server run with :9000 and :443") @@ -48,4 +45,4 @@ func setCertPath() (string ,string) { fmt.Println(sslCertKeyPath) return sslCertCrtPath, sslCertKeyPath } -
kenng created this gist
Jul 12, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ package main import ( "log" "net/http" "os" "fmt" ) // usage: <program> <ssl-directory> <cert-crt-filename> <cert-key-filename> func main() { currentDir, _ := os.Getwd() fmt.Println("currentDir:" + currentDir) sslCertCrtName, sslCertKeyName := setCertPath() // create file server handler fs := http.FileServer(http.Dir(currentDir)) // start HTTP server with `fs` as the default handler fmt.Println("server run with :9000 and :443") log.Fatal(http.ListenAndServeTLS(":443", sslCertCrtName, sslCertKeyName, fs)) log.Fatal(http.ListenAndServe(":9000", fs)) } func setCertPath() (string ,string) { args := os.Args[1:] homeDir, err := os.UserHomeDir() if err != nil {log.Fatal("error in getting home directory")} fmt.Println("home directory: " + homeDir) sslCertDir := homeDir + "/ssl-local-cert" sslCertCrtName := "test.iw.com.pem" sslCertKeyName := "test.iw.com-key.pem" if (len(args) >= 1) { sslCertDir = args[0] } if (len(args) >= 2) { sslCertCrtName = args[1] } if (len(args) >= 3) { sslCertKeyName = args[2] } if (string(sslCertCrtName[0]) != "/") { sslCertCrtName = "/" + sslCertCrtName } if (string(sslCertKeyName[0]) != "/") { sslCertKeyName = "/" + sslCertKeyName } sslCertCrtPath := sslCertDir + sslCertCrtName sslCertKeyPath := sslCertDir + sslCertKeyName fmt.Println(sslCertCrtPath) fmt.Println(sslCertKeyPath) return sslCertCrtPath, sslCertKeyPath }