added better server handling and branch support
This commit is contained in:
parent
cfb953c6cb
commit
025e339d7a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
data/
|
data/
|
||||||
comments.db/
|
comments.db/
|
||||||
|
notes
|
26
README.md
26
README.md
@ -1,8 +1,13 @@
|
|||||||
H0wdy!!!
|
H0wdy!!!
|
||||||
|
|
||||||
feel free to commit, leave suggestions, issues, or really anything <3
|
feel free to commit, leave suggestions/ideas, issues, or really anything <3
|
||||||
|
|
||||||
## SETUP
|
# What is TCP.WIKI ?
|
||||||
|
|
||||||
|
## Project Goals
|
||||||
|
secure and verifiable wiki for projects, code, courses, documents, articles, tutorials, and more
|
||||||
|
|
||||||
|
## Setup
|
||||||
**For a normal user you can follow this process:**
|
**For a normal user you can follow this process:**
|
||||||
|
|
||||||
First clone the repo:
|
First clone the repo:
|
||||||
@ -27,28 +32,37 @@ Then cd and run dev.sh
|
|||||||
cd tcp-wiki
|
cd tcp-wiki
|
||||||
bash dev.sh
|
bash dev.sh
|
||||||
```
|
```
|
||||||
|
Then you just have to execute this to run the server:
|
||||||
|
```go
|
||||||
|
cd src && go run .
|
||||||
|
```
|
||||||
Then you goto your browser and visit: http://127.0.0.1:8080/
|
Then you goto your browser and visit: http://127.0.0.1:8080/
|
||||||
|
|
||||||
This method just adds in some handy symlinks for development purposes
|
This method just adds in some handy symlinks for development purposes
|
||||||
|
|
||||||
### Use with your own repo?
|
## Want to use with your own repo?
|
||||||
|
|
||||||
All you have to do is modify the main.go file:
|
All you have to do is modify the following lines in the src/main.go file:
|
||||||
```go
|
```go
|
||||||
const repoURL = "https://git.tcp.direct/S4D/tcp-wiki.git"
|
const repoURL = "https://git.tcp.direct/S4D/tcp-wiki.git"
|
||||||
```
|
```
|
||||||
Change this line to your repo link, and enjoy!
|
Change `https://git.tcp.direct/S4D/tcp-wiki.git` to your repo link, and:
|
||||||
|
```go
|
||||||
|
const repoBRANCH = "main"
|
||||||
|
```
|
||||||
|
change `main` to your specific repo's branch and you should be good to go!
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [ ] MANY FUCKING THINGS
|
- [ ] MANY FUCKING THINGS
|
||||||
- [ ] Webhook support for auto pull on push/update of the git repo
|
- [ ] Webhook support for auto pull on push/update of the git repo
|
||||||
- [ ] Git Branch support
|
- [x] Git Branch support
|
||||||
- [ ] add a star/upvote/like feature for pages
|
- [ ] add a star/upvote/like feature for pages
|
||||||
- [ ] edit tracker
|
- [ ] edit tracker
|
||||||
- [ ] Author
|
- [ ] Author
|
||||||
- [ ] last edited
|
- [ ] last edited
|
||||||
- [ ] last editor/commit
|
- [ ] last editor/commit
|
||||||
|
- [ ] PGP Signed & Verification
|
||||||
- [ ] pgp signed intergration
|
- [ ] pgp signed intergration
|
||||||
- [x] comments using bitcask - generated in comments.db/
|
- [x] comments using bitcask - generated in comments.db/
|
||||||
- [ ] verification - no login pgp
|
- [ ] verification - no login pgp
|
||||||
|
26
dev.sh
26
dev.sh
@ -1,14 +1,22 @@
|
|||||||
#/bin/bash
|
#/bin/bash
|
||||||
# this sets up super annoying shit like hard symlinks and whatever else
|
# this sets up super annoying shit like hard symlinks and whatever else
|
||||||
# Eventually front end will be in a seperate branch for production
|
|
||||||
# but for now we can manage by editing via hardlinks.
|
# but for now we can manage by editing via hardlinks.
|
||||||
# This sets up your local readme as the main page and the files in assets as public
|
# This sets up your local readme as the main page and the files in assets as public
|
||||||
cd src && go run .
|
|
||||||
rm ../data/assets/*
|
|
||||||
ln ../assets/_layout.html ../data/assets/_layout.html
|
|
||||||
ln ../assets/main.css ../data/assets/main.css
|
|
||||||
rm ../data/README.md
|
|
||||||
ln ../README.md ../data/README.md
|
|
||||||
echo "Developer setup ready!"
|
|
||||||
echo "Goto: http://127.0.0.1:8080"
|
|
||||||
|
|
||||||
|
# Clone the repository
|
||||||
|
echo "Press Control+C when prompted"
|
||||||
|
go run ./src
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Set up hard links
|
||||||
|
# !!! for main branch only !!!
|
||||||
|
rm data/assets/*
|
||||||
|
ln assets/_layout.html data/assets/_layout.html
|
||||||
|
ln assets/main.css data/assets/main.css
|
||||||
|
rm data/README.md
|
||||||
|
ln README.md data/README.md
|
||||||
|
|
||||||
|
echo "Developer setup ready!"
|
||||||
|
echo "Go ahead and run go run src/"
|
||||||
|
echo "And Go to: http://127.0.0.1:8080"
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
git "github.com/go-git/go-git/v5"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cloneRepository(repoURL, localPath string) error {
|
func cloneRepository(repoURL, localPath string) error {
|
||||||
@ -16,7 +17,7 @@ func cloneRepository(repoURL, localPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func pullRepository(localPath string) error {
|
func pullRepository(localPath, branch string) error {
|
||||||
repo, err := git.PlainOpen(localPath)
|
repo, err := git.PlainOpen(localPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -27,7 +28,10 @@ func pullRepository(localPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = worktree.Pull(&git.PullOptions{RemoteName: "origin"})
|
err = worktree.Pull(&git.PullOptions{
|
||||||
|
RemoteName: "origin",
|
||||||
|
ReferenceName: plumbing.NewBranchReferenceName(branch),
|
||||||
|
})
|
||||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
33
src/main.go
33
src/main.go
@ -1,15 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/prologic/bitcask"
|
"github.com/prologic/bitcask"
|
||||||
)
|
)
|
||||||
|
|
||||||
const repoURL = "https://git.tcp.direct/S4D/tcp-wiki.git"
|
const repoURL = "https://git.tcp.direct/S4D/tcp-wiki.git"
|
||||||
|
const repoBRANCH = "main"
|
||||||
const localPath = "../data"
|
const localPath = "../data"
|
||||||
|
|
||||||
var commentsDB *bitcask.Bitcask
|
var commentsDB *bitcask.Bitcask
|
||||||
@ -28,7 +35,29 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
http.HandleFunc("/submit_comment", submitCommentHandler)
|
http.HandleFunc("/submit_comment", submitCommentHandler)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
|
srv := &http.Server{Addr: ":8080"}
|
||||||
|
go func() {
|
||||||
|
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Fatalf("ListenAndServe() failed: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
fmt.Println("Server running at http://127.0.0.1:8080")
|
||||||
|
fmt.Println("Press Ctrl-C to stop the server")
|
||||||
|
|
||||||
|
// Wait for interrupt signal to stop the server
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
<-c
|
||||||
|
|
||||||
|
// Shutdown the server gracefully
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
if err := srv.Shutdown(ctx); err != nil {
|
||||||
|
log.Fatalf("Server Shutdown failed: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Println("Server stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -41,7 +70,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := pullRepository(localPath)
|
err := pullRepository(localPath, repoBRANCH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to pull repository: %v", err)
|
log.Printf("Failed to pull repository: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user