Начал пытаться что-то написать на JS. Ненавижу JS
This commit is contained in:
parent
3760787091
commit
9dbcc53fd1
6 changed files with 39 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -25,3 +25,6 @@ go.work
|
|||
images/
|
||||
|
||||
main
|
||||
node_modules
|
||||
dist
|
||||
bun.lockb
|
|
@ -2,7 +2,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>CatGirls Town</title>
|
||||
<link rel="stylesheet" href="static/picnic.min.css">
|
||||
<link rel="stylesheet" href="src/picnic.min.css">
|
||||
<script type="module" src="src/main.js"></script>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -34,7 +35,7 @@
|
|||
</div>
|
||||
<div class="flex ">
|
||||
<article class="card">
|
||||
<img src="images/{{ . }}">
|
||||
<img id="CatGirlPicture" onclick="getRandomPicture()" src="images/{{ . }}">
|
||||
</article>
|
||||
</div>
|
||||
<div class="flex"></div>
|
14
main.go
14
main.go
|
@ -7,6 +7,7 @@ import (
|
|||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
@ -30,6 +31,11 @@ func GetRandImg() string {
|
|||
return picsArray[rand.Intn(len(picsArray))]
|
||||
}
|
||||
|
||||
func ReturnPicFilename(w http.ResponseWriter, req *http.Request) {
|
||||
var picFilename io.Reader = strings.NewReader(GetRandImg())
|
||||
io.Copy(w, picFilename)
|
||||
}
|
||||
|
||||
func ReturnPic(w http.ResponseWriter, req *http.Request) {
|
||||
picture, _ := os.Open(fmt.Sprintf("images/%v", GetRandImg()))
|
||||
var pictureReader io.Reader = picture
|
||||
|
@ -38,7 +44,7 @@ func ReturnPic(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
func ReturnHTML(w http.ResponseWriter, req *http.Request) {
|
||||
htmlOpen, err := template.ParseFiles("main.html")
|
||||
htmlOpen, err := template.ParseFiles("dist/index.html")
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
return
|
||||
|
@ -51,9 +57,11 @@ func ReturnHTML(w http.ResponseWriter, req *http.Request) {
|
|||
func main() {
|
||||
log.Println("Server Start")
|
||||
imagesDir := http.FileServer(http.Dir("images"))
|
||||
staticDir := http.FileServer(http.Dir("static"))
|
||||
staticDir := http.FileServer(http.Dir("dist/assets"))
|
||||
http.Handle("/images/", http.StripPrefix("/images/", imagesDir))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", staticDir))
|
||||
http.Handle("/assets/", http.StripPrefix("/assets/", staticDir))
|
||||
|
||||
http.HandleFunc("/rand", ReturnPicFilename)
|
||||
http.HandleFunc("/", ReturnHTML)
|
||||
http.ListenAndServe(":3666", nil)
|
||||
}
|
||||
|
|
15
package.json
Normal file
15
package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "picRan",
|
||||
"private": "true",
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.1",
|
||||
"axios": "1.7.9"
|
||||
}
|
||||
}
|
7
src/main.js
Normal file
7
src/main.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import axios from "axios";
|
||||
|
||||
let pictureId = document.getElementById("CatGirlPicture")
|
||||
pictureId.onclick = function() {
|
||||
let picFilename = axios.get(location.href + "rand")
|
||||
console.log(picFilename)
|
||||
}
|
0
static/picnic.min.css → src/picnic.min.css
vendored
0
static/picnic.min.css → src/picnic.min.css
vendored
Loading…
Reference in a new issue