소스 검색

init project

Help-14 3 년 전
부모
커밋
cd5983d1b8
9개의 변경된 파일190개의 추가작업 그리고 41개의 파일을 삭제
  1. 2 7
      .vscode/launch.json
  2. 17 0
      src/.vscode/launch.json
  3. 21 0
      src/go.mod
  4. 52 0
      src/go.sum
  5. 40 0
      src/main.go
  6. 0 23
      src/main.ts
  7. 49 0
      src/modules/config.go
  8. 0 11
      src/public/config.json
  9. 9 0
      src/public/config.yaml

+ 2 - 7
.vscode/launch.json

@@ -5,18 +5,13 @@
             "request": "launch",
             "request": "launch",
             "name": "Launch Program",
             "name": "Launch Program",
             "type": "pwa-node",
             "type": "pwa-node",
-            "program": "${workspaceFolder}/src/main.ts",
+            "program": "main.go",
             "cwd": "${workspaceFolder}/src",
             "cwd": "${workspaceFolder}/src",
-            "runtimeExecutable": "deno",
+            "runtimeExecutable": "go",
             "runtimeArgs": [
             "runtimeArgs": [
                 "run",
                 "run",
-                "--inspect",
-                "--allow-net",
-                "--allow-read",
-                "--allow-write",
             ],
             ],
             "outputCapture": "std",
             "outputCapture": "std",
-            "attachSimplePort": 9229
         },
         },
         {
         {
             "request": "launch",
             "request": "launch",

+ 17 - 0
src/.vscode/launch.json

@@ -0,0 +1,17 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "request": "launch",
+            "name": "Launch Program",
+            "type": "pwa-node",
+            "program": "main.go",
+            "cwd": "${workspaceFolder}",
+            "runtimeExecutable": "go",
+            "runtimeArgs": [
+                "run",
+            ],
+            "outputCapture": "std",
+        }
+    ]
+}

+ 21 - 0
src/go.mod

@@ -0,0 +1,21 @@
+module github.com/help-14/magma
+
+go 1.18
+
+require (
+	github.com/fsnotify/fsnotify v1.5.1 // indirect
+	github.com/hashicorp/hcl v1.0.0 // indirect
+	github.com/magiconair/properties v1.8.5 // indirect
+	github.com/mitchellh/mapstructure v1.4.3 // indirect
+	github.com/pelletier/go-toml v1.9.4 // indirect
+	github.com/spf13/afero v1.6.0 // indirect
+	github.com/spf13/cast v1.4.1 // indirect
+	github.com/spf13/jwalterweatherman v1.1.0 // indirect
+	github.com/spf13/pflag v1.0.5 // indirect
+	github.com/spf13/viper v1.10.1 // indirect
+	github.com/subosito/gotenv v1.2.0 // indirect
+	golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
+	golang.org/x/text v0.3.7 // indirect
+	gopkg.in/ini.v1 v1.66.2 // indirect
+	gopkg.in/yaml.v2 v2.4.0 // indirect
+)

+ 52 - 0
src/go.sum

@@ -0,0 +1,52 @@
+github.com/creasty/defaults v1.5.2 h1:/VfB6uxpyp6h0fr7SPp7n8WJBoV8jfxQXPCnkVSjyls=
+github.com/creasty/defaults v1.5.2/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
+github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
+github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
+github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
+github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
+github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
+github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
+github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
+github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
+github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
+github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
+github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
+github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
+github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
+github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
+github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
+github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211210111614-af8b64212486 h1:5hpz5aRr+W1erYCL5JRhSUBJRph7l9XkNveoExlrKYk=
+golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
+gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

+ 40 - 0
src/main.go

@@ -0,0 +1,40 @@
+package main
+
+import (
+	"html/template"
+	"log"
+	"net/http"
+	"path/filepath"
+
+	config "github.com/help-14/magma/modules"
+)
+
+func main() {
+	//fs := http.FileServer(http.Dir("./temp"))
+	//http.Handle("/static/", http.StripPrefix("/static/", fs))
+	//http.Handle("/", fs)
+	//http.HandleFunc("/", serveTemplate)
+
+	config.LoadConfig()
+
+	log.Println("Listening on :7001 ...")
+	err := http.ListenAndServe(":7001", nil)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
+
+func serveTemplate(w http.ResponseWriter, r *http.Request) {
+	lp := filepath.Join("templates", "layout.html")
+	fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
+
+	tmpl, _ := template.ParseFiles(lp, fp)
+	tmpl.ExecuteTemplate(w, "layout", nil)
+}
+
+// templ.Execute(file, struct {
+//     Age int
+//     Name string
+// }{42, "Dolphin"})
+
+// {{.Age}}, {{.Name}}

+ 0 - 23
src/main.ts

@@ -1,23 +0,0 @@
-import { Config, loadConfig } from "./modules/config.ts";
-import { startServer } from "./modules/server.ts";
-import { Language } from "./modules/language.ts";
-
-declare global {
-  var config: Config;
-  var index: string;
-  var language: Language;
-  interface Window {
-    config: any;
-    index: string;
-    language: any;
-  }
-}
-
-window.config = await loadConfig();
-if (window.config === null) {
-  console.error("Failed to load config file.");
-  console.info("Using default config.");
-  window.config = new Config();
-}
-
-startServer();

+ 49 - 0
src/modules/config.go

@@ -0,0 +1,49 @@
+package config
+
+type YamlConfig struct {
+	website WebsiteConfig
+	addons  []string
+}
+
+type WebsiteConfig struct {
+	title        string
+	description  string
+	language     string
+	localization string
+	useMetric    bool
+	theme        string
+}
+
+func LoadConfig() YamlConfig {
+	defaultConfig := YamlConfig{
+		website: WebsiteConfig{
+			title:        "Magma Dashboard",
+			description:  "",
+			language:     "en",
+			localization: "en-us",
+			useMetric:    true,
+			theme:        "flame",
+		},
+		addons: []string{},
+	}
+
+	// yamlFile, err := ioutil.ReadFile("./public/config.yaml")
+	// if err != nil {
+	// 	fmt.Printf("Error reading YAML file: %s\n", err)
+	// 	return defaultConfig
+	// }
+	return defaultConfig
+	// fmt.Printf("YAML file: %s\n", yamlFile)
+
+	// var yamlConfig YamlConfig
+	// err = yaml.Unmarshal(yamlFile, &yamlConfig)
+	// if err != nil {
+	// 	fmt.Printf("Error parsing YAML file: %s\n", err)
+	// 	return defaultConfig
+	// }
+
+	// fmt.Printf(yamlConfig.website.title)
+	// fmt.Printf("%+v\n", yamlConfig)
+	// fmt.Printf("%+v\n", defaultConfig)
+	// return yamlConfig
+}

+ 0 - 11
src/public/config.json

@@ -1,11 +0,0 @@
-{
-    "website": {
-        "theme": "flame",
-        "title": "Magma Dashboard",
-        "description": "",
-        "language": "en",
-        "localization": "en-us",
-        "useMetric": true
-    },
-    "addons": []
-}

+ 9 - 0
src/public/config.yaml

@@ -0,0 +1,9 @@
+website:
+  theme: "flame"
+  title: "Help-14 Dashboard"
+  description: ""
+  language: "vi"
+  localization: "vi-vn"
+  useMetric: true
+
+addons: