Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sammo12 authored Aug 10, 2023
1 parent 9e87326 commit cbcb100
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions ghost.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"encoding/json"
"strings"
)

type Dbconfig struct {
Expand All @@ -21,14 +22,12 @@ func Init() {
}
}
content, errd := ioutil.ReadFile("dbconfig.json")
if errd != nil {
fmt.Println(errd)
}
if errd != nil {}
json.Unmarshal([]byte(string(content)), &conf)
}
func Set(coll string, key string, val string) {
chk := "./.DB/."+coll
khk := chk+"/"+key+".ln"
khk := chk+"/"+key+".[]"
khkb := []byte(val)
if _,error := os.Stat(chk); os.IsNotExist(error) {
os.Mkdir(chk,0700)
Expand All @@ -39,7 +38,7 @@ func Set(coll string, key string, val string) {
}
func Get(coll string, key string) string{
chk := "./.DB/."+coll
khk := chk+"/"+key+".ln"
khk := chk+"/"+key+".[]"
out,err:=ioutil.ReadFile(khk)
if err!= nil{
fmt.Println(err)
Expand All @@ -48,7 +47,7 @@ func Get(coll string, key string) string{
}
func Del(coll string, key string){
chk := "./.DB/."+coll
khk := chk+"/"+key+".ln"
khk := chk+"/"+key+".[]"
os.Remove(khk)
}
func Delcol(coll string){
Expand All @@ -57,10 +56,28 @@ func Delcol(coll string){
}
func Update(coll string,key string,val string) {
chk := "./.DB/."+coll
khk := chk+"/"+key+".ln"
khk := chk+"/"+key+".[]"
khkb := []byte(val)
err:=ioutil.WriteFile(khk,khkb,0)
if err!=nil{
fmt.Println(err)
}
}
func Getall(coll string) []string{
chk := "./.DB/."+coll
files, _ := ioutil.ReadDir(chk)
var k []string
for _, f := range files {
if strings.HasSuffix(f.Name(), ".[]") {
k=append(k,f.Name())
}
}
i:=len(k)
for j:=0;j<i;j++ {
k[j]=strings.TrimRight(k[j], ".[]")
}
for m:=0;m<i;m++{
k[m]=Get(coll,k[m])
}
return k
}

0 comments on commit cbcb100

Please sign in to comment.