Parse flags and check server error with Is

This commit is contained in:
Melon 2023-11-17 09:09:11 +00:00
parent a431e506ec
commit 720e413336
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
7 changed files with 5 additions and 120 deletions

79
.gitignore vendored
View File

@ -21,81 +21,4 @@
# Go workspace file # Go workspace file
go.work go.work
### GoLand template .idea/
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

8
.idea/.gitignore vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/site-hosting.iml" filepath="$PROJECT_DIR$/.idea/site-hosting.iml" />
</modules>
</component>
</project>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"flag" "flag"
"fmt" "fmt"
"github.com/1f349/site-hosting/config" "github.com/1f349/site-hosting/config"
@ -25,6 +26,8 @@ var (
func main() { func main() {
flag.StringVar(&listenFlag, "listen", "", "Address to listen on") flag.StringVar(&listenFlag, "listen", "", "Address to listen on")
flag.StringVar(&storageFlag, "storage", "", "Path site files are stored in") flag.StringVar(&storageFlag, "storage", "", "Path site files are stored in")
flag.Parse()
if listenFlag == "" { if listenFlag == "" {
log.Fatal("[SiteHosting] Missing listen flag") log.Fatal("[SiteHosting] Missing listen flag")
} }
@ -54,7 +57,7 @@ func main() {
go func() { go func() {
err := srv.ListenAndServe() err := srv.ListenAndServe()
if err != nil { if err != nil {
if err == http.ErrServerClosed { if errors.Is(err, http.ErrServerClosed) {
log.Printf("[SiteHosting] The http server shutdown successfully\n") log.Printf("[SiteHosting] The http server shutdown successfully\n")
} else { } else {
log.Printf("[SiteHosting] Error trying to host the http server: %s\n", err.Error()) log.Printf("[SiteHosting] Error trying to host the http server: %s\n", err.Error())