-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from r1c0n/1.3.0
1.3.0 rc1
- Loading branch information
Showing
7 changed files
with
81 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"repo_config": { | ||
"version": "1.3.0", | ||
"author": "recon (contact@mail.recon.best)", | ||
"product": "Gamma Web Server", | ||
"repository": "https://github.com/gamma-gws/gws" | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/inancgumus/screen" | ||
) | ||
|
||
type Config struct { | ||
Port string `json:"port"` | ||
Domain string `json:"domain"` | ||
StaticDir string `json:"static_dir"` | ||
TLSConfig struct { | ||
CertFile string `json:"cert_file"` | ||
KeyFile string `json:"key_file"` | ||
} `json:"tls_config"` | ||
RepoConfig struct { | ||
Version string `json:"version"` | ||
Author string `json:"author"` | ||
Product string `json:"product"` | ||
Repository string `json:"repository"` | ||
} `json:"repo_config"` | ||
} | ||
|
||
func main() { | ||
config := loadConfig("config.json") | ||
|
||
printHeader(config) | ||
startServer(config) | ||
} | ||
|
||
func loadConfig(filename string) Config { | ||
configData, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var config Config | ||
if err := json.Unmarshal(configData, &config); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return config | ||
} | ||
|
||
func printHeader(config Config) { | ||
screen.Clear() | ||
fmt.Printf("Hello, World! | %s v%s | Created by %s\n", config.RepoConfig.Product, config.RepoConfig.Version, config.RepoConfig.Author) | ||
fmt.Printf("To contribute, check out our GitHub repo: %s\n", config.RepoConfig.Repository) | ||
fmt.Println("----------------------------------------------------------------------------") | ||
fmt.Printf("To exit the program, enter the key combination \"CTRL + C\".\n") | ||
fmt.Printf("Site URL: http://%s%s\n", config.Domain, config.Port) | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/inancgumus/screen" | ||
) | ||
|
||
type Config struct { | ||
Port string `json:"port"` // Port is the port number that the server will listen on. | ||
Domain string `json:"domain"` // Domain represents the hostname or address of the server. | ||
StaticDir string `json:"static_dir"` // StaticDir is the directory where static assets (e.g. HTML, CSS, JavaScript) are stored. | ||
func startServer(config Config) { | ||
r := mux.NewRouter() | ||
|
||
// TLSConfig contains configuration options for TLS (Transport Layer Security). | ||
TLSConfig struct { | ||
CertFile string `json:"cert_file"` // CertFile is the path to the TLS certificate file. | ||
KeyFile string `json:"key_file"` // KeyFile is the path to the TLS key file. | ||
} `json:"tls_config"` | ||
|
||
// RepoConfig contains information about the repository. | ||
RepoConfig struct { | ||
Version string `json:"version"` // Version is the version of the repository. | ||
Author string `json:"author"` // Author is the author of the repository. | ||
Product string `json:"product"` // Product is the name of the product that the repository is for. | ||
Repository string `json:"repository"` // Repository is the name of the repository. | ||
} `json:"repo_config"` | ||
} | ||
|
||
func main() { | ||
// Read the configuration file | ||
configData, err := ioutil.ReadFile("config.json") | ||
if err != nil { | ||
log.Fatal(err) // If there is an error reading the file, log the error and exit the program. | ||
} | ||
|
||
// Parse the configuration data into a Config struct. | ||
var config Config | ||
if err := json.Unmarshal(configData, &config); err != nil { | ||
log.Fatal(err) // If there is an error parsing the data, log the error and exit the program. | ||
} | ||
|
||
// Clear the screen. | ||
screen.Clear() | ||
|
||
// Print a message coontaining information from the Config struct. Mostly repository information. | ||
fmt.Print("Hello, World! | ", config.RepoConfig.Product, " v", config.RepoConfig.Version, " | Created by ", config.RepoConfig.Author) | ||
fmt.Print("\nTo contribute, check out our GitHub repo: ", config.RepoConfig.Repository, ".") | ||
fmt.Print("\n----------------------------------------------------------------------------\n") | ||
fmt.Print("To exit the program, enter the key combination \"CTRL + C\".\n") | ||
fmt.Print("Site URL: http://", config.Domain, config.Port, "\n") | ||
|
||
r := mux.NewRouter() // Create a new router. | ||
|
||
// Set up a FileServer to serve static assets. | ||
fs := http.FileServer(http.Dir(config.StaticDir)) | ||
r.PathPrefix("/").Handler(http.StripPrefix("/", fs)) | ||
|
||
// Start the server. | ||
http.ListenAndServe(config.Port, r) | ||
} |