Skip to content

Commit

Permalink
updated code for latest Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed May 7, 2024
1 parent c892d26 commit 872500f
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

#RUN sudo apt-get update
RUN apt-get update
Expand Down
2 changes: 1 addition & 1 deletion data/contentStore/home.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"home","title":"Home Page","subject":"Ulbora CMS","author":"Ken Williamson","createDate":"2020-04-09T12:32:39.806769116-04:00","modifiedDate":"2024-05-06T15:41:07.817101117-04:00","hits":241,"metaAuthorName":"","metaDesc":"","metaKeyWords":"UlboraCMS, CMS, Ulbora, templates, screens","metaRobotKeyWords":"","text":"PHA+QSBUaGVtZSBmb3IgVWxib3JhIENNUyBhbmQgdGhlcmUgYXJlIG90aGVycy48L3A+","TextHTML":"","archived":false,"visible":true,"UseModifiedDate":false,"blogPost":false}
{"name":"home","title":"Home Page","subject":"Ulbora CMS","author":"Ken Williamson","createDate":"2020-04-09T12:32:39.806769116-04:00","modifiedDate":"2024-05-07T13:50:27.531145872-04:00","hits":242,"metaAuthorName":"","metaDesc":"","metaKeyWords":"UlboraCMS, CMS, Ulbora, templates, screens","metaRobotKeyWords":"","text":"PHA+QSBUaGVtZSBmb3IgVWxib3JhIENNUyBhbmQgdGhlcmUgYXJlIG90aGVycy48L3A+","TextHTML":"","archived":false,"visible":true,"UseModifiedDate":false,"blogPost":false}
4 changes: 2 additions & 2 deletions handlers/adminBackupHandler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -87,7 +87,7 @@ func (h *CmsHandler) AdminUploadBackups(w http.ResponseWriter, r *http.Request)

//h.Log.Debug("image file : ", *handler)

bkdata, rferr := ioutil.ReadAll(file)
bkdata, rferr := io.ReadAll(file)
h.Log.Debug("read file err: ", rferr)

h.Log.Debug("handler.Filename: ", handler.Filename)
Expand Down
4 changes: 2 additions & 2 deletions handlers/adminImageHandler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"io/ioutil"
"io"
"net/http"

mux "github.com/GolangToolKits/grrt"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (h *CmsHandler) AdminUploadImage(w http.ResponseWriter, r *http.Request) {
defer file.Close()
//h.Log.Debug("image file : ", *handler)

data, rferr := ioutil.ReadAll(file)
data, rferr := io.ReadAll(file)
h.Log.Debug("read file err: ", rferr)

h.Log.Debug("handler.Filename: ", handler.Filename)
Expand Down
4 changes: 2 additions & 2 deletions handlers/adminTemplateHandler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -60,7 +60,7 @@ func (h *CmsHandler) AdminUploadTemplate(w http.ResponseWriter, r *http.Request)
defer tfile.Close()
//h.Log.Debug("template file : ", *handler)

data, rferr := ioutil.ReadAll(tfile)
data, rferr := io.ReadAll(tfile)
h.Log.Debug("read file err: ", rferr)

i := strings.Index(handler.Filename, ".")
Expand Down
2 changes: 1 addition & 1 deletion handlers/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCmsHandler_ProcessBody(t *testing.T) {
robj.Valid = true
robj.Code = "3"
// var res http.Response
// res.Body = ioutil.NopCloser(bytes.NewBufferString(`{"valid":true, "code":"1"}`))
// res.Body = io.NopCloser(bytes.NewBufferString(`{"valid":true, "code":"1"}`))
var sURL = "http://localhost/test"
aJSON, _ := json.Marshal(robj)
r, _ := http.NewRequest("POST", sURL, bytes.NewBuffer(aJSON))
Expand Down
34 changes: 17 additions & 17 deletions handlers/loggingHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
Expand All @@ -22,7 +22,7 @@ func TestCmsHandler_SetLogLevel(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -32,7 +32,7 @@ func TestCmsHandler_SetLogLevel(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -48,7 +48,7 @@ func TestCmsHandler_SetLogLevelBadReq(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
//aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
//aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", nil)
Expand All @@ -58,7 +58,7 @@ func TestCmsHandler_SetLogLevelBadReq(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -74,7 +74,7 @@ func TestCmsHandler_SetInfoLogLevel(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"info"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"info"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -84,7 +84,7 @@ func TestCmsHandler_SetInfoLogLevel(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -100,7 +100,7 @@ func TestCmsHandler_SetAllLogLevel(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"all"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"all"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -110,7 +110,7 @@ func TestCmsHandler_SetAllLogLevel(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -126,7 +126,7 @@ func TestCmsHandler_SetOffLogLevel(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -136,7 +136,7 @@ func TestCmsHandler_SetOffLogLevel(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -153,7 +153,7 @@ func TestCmsHandler_SetOffLogLevelLogKey(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -163,7 +163,7 @@ func TestCmsHandler_SetOffLogLevelLogKey(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -181,7 +181,7 @@ func TestCmsHandler_SetOffLogLevelLogWrongKey(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -191,7 +191,7 @@ func TestCmsHandler_SetOffLogLevelLogWrongKey(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand All @@ -217,7 +217,7 @@ func TestCmsHandler_SetOffLogLevelBadMedia(t *testing.T) {
oh.Log = &logger

h := oh.GetNew()
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
//aJSON, _ := json.Marshal(robj)
//fmt.Println("aJSON: ", aJSON)
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
Expand All @@ -227,7 +227,7 @@ func TestCmsHandler_SetOffLogLevelBadMedia(t *testing.T) {
w := httptest.NewRecorder()
h.SetLogLevel(w, r)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
var lres LogResponse
json.Unmarshal(body, &lres)
fmt.Println("body: ", string(body))
Expand Down
Binary file modified main
Binary file not shown.
29 changes: 14 additions & 15 deletions services/backupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"compress/zlib"
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -20,22 +19,22 @@ const (
templateFiles = "templateFiles"
)

//BackupFiles BackupFiles
// BackupFiles BackupFiles
type BackupFiles struct {
ContentStoreFiles *[]BackupFile
TemplateStoreFiles *[]BackupFile
ImageFiles *[]BackupFile
TemplateFiles *BackupFile
}

//BackupFile BackupFile
// BackupFile BackupFile
type BackupFile struct {
FilesLocation string
Name string
FileData []byte
}

//UploadBackups UploadBackups
// UploadBackups UploadBackups
func (c *CmsService) UploadBackups(bk *[]byte) bool {
var rtn bool
var bkfs BackupFiles
Expand All @@ -59,7 +58,7 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
for _, cf := range *bkfs.ContentStoreFiles {
c.Log.Debug("BackupFile content file name: ", c.ContentStorePath+string(filepath.Separator)+cf.Name)
c.Log.Debug("BackupFile content file: ", cf)
werr := ioutil.WriteFile(c.ContentStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
werr := os.WriteFile(c.ContentStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
c.Log.Debug("BackupFile content file write err : ", werr)
}

Expand All @@ -72,7 +71,7 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
for _, cf := range *bkfs.TemplateStoreFiles {
c.Log.Debug("BackupFile template file name: ", c.TemplateStorePath+string(filepath.Separator)+cf.Name)
c.Log.Debug("BackupFile template file: ", cf)
werr := ioutil.WriteFile(c.TemplateStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
werr := os.WriteFile(c.TemplateStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
c.Log.Debug("BackupFile template file write err : ", werr)
}

Expand All @@ -85,7 +84,7 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
for _, cf := range *bkfs.ImageFiles {
c.Log.Debug("BackupFile image file name: ", c.ImagePath+string(filepath.Separator)+cf.Name)
c.Log.Debug("BackupFile image file: ", cf)
werr := ioutil.WriteFile(c.ImagePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
werr := os.WriteFile(c.ImagePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
c.Log.Debug("BackupFile image file write err : ", werr)
}

Expand Down Expand Up @@ -114,19 +113,19 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
return rtn
}

//DownloadBackups DownloadBackups
// DownloadBackups DownloadBackups
func (c *CmsService) DownloadBackups() (bool, *[]byte) {
var rtn bool
var bkfs BackupFiles

//contentStore
var contStoreFiles []BackupFile
cntfiles, err := ioutil.ReadDir(c.ContentStorePath)
cntfiles, err := os.ReadDir(c.ContentStorePath)
if err == nil {
for _, sfile := range cntfiles {
if !sfile.IsDir() {
c.Log.Debug("content store file: ", c.ContentStorePath+string(filepath.Separator)+sfile.Name())
fileData, rerr := ioutil.ReadFile(c.ContentStorePath + string(filepath.Separator) + sfile.Name())
fileData, rerr := os.ReadFile(c.ContentStorePath + string(filepath.Separator) + sfile.Name())
//c.Log.Debug("content store file data: ", fileData)
if rerr == nil {
var cbk BackupFile
Expand All @@ -143,12 +142,12 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {

//templateStore
var templateStoreFiles []BackupFile
tempfiles, err := ioutil.ReadDir(c.TemplateStorePath)
tempfiles, err := os.ReadDir(c.TemplateStorePath)
if err == nil {
for _, sfile := range tempfiles {
if !sfile.IsDir() {
c.Log.Debug("template store file: ", c.TemplateStorePath+string(filepath.Separator)+sfile.Name())
fileData, rerr := ioutil.ReadFile(c.TemplateStorePath + string(filepath.Separator) + sfile.Name())
fileData, rerr := os.ReadFile(c.TemplateStorePath + string(filepath.Separator) + sfile.Name())
c.Log.Debug("template store file data: ", fileData)
if rerr == nil {
var cbk BackupFile
Expand All @@ -165,13 +164,13 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {

//images
var imageFiles []BackupFile
imgfiles, err := ioutil.ReadDir(c.ImagePath)
imgfiles, err := os.ReadDir(c.ImagePath)
if err == nil {
c.Log.Debug("imgfiles: ", imgfiles)
for _, sfile := range imgfiles {
if !sfile.IsDir() {
c.Log.Debug("image file: ", c.ImagePath+string(filepath.Separator)+sfile.Name())
fileData, rerr := ioutil.ReadFile(c.ImagePath + string(filepath.Separator) + sfile.Name())
fileData, rerr := os.ReadFile(c.ImagePath + string(filepath.Separator) + sfile.Name())
if rerr == nil {
var cbk BackupFile
cbk.Name = sfile.Name()
Expand All @@ -190,7 +189,7 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {
var buf bytes.Buffer
zr := gzip.NewWriter(&buf)
tw := tar.NewWriter(zr)
files, err := ioutil.ReadDir(c.TemplateFilePath)
files, err := os.ReadDir(c.TemplateFilePath)
if err == nil {
for _, file := range files {
if file.IsDir() {
Expand Down
5 changes: 2 additions & 3 deletions services/backupService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/zlib"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -43,7 +42,7 @@ func TestCmsService_DownloadBackups(t *testing.T) {

func TestCmsService_UploadBackups(t *testing.T) {

fileData, rerr := ioutil.ReadFile("./testBackupZips/compress.dat")
fileData, rerr := os.ReadFile("./testBackupZips/compress.dat")
fmt.Println(rerr)

var b bytes.Buffer
Expand All @@ -54,7 +53,7 @@ func TestCmsService_UploadBackups(t *testing.T) {
io.Copy(&out, r)
r.Close()
rtn := out.Bytes()
ioutil.WriteFile("./testBackupZips/uncompress.json", rtn, 0644)
os.WriteFile("./testBackupZips/uncompress.json", rtn, 0644)
}
var cs CmsService
cs.ContentStorePath = "./testBackupRestore/contentStore"
Expand Down
Loading

0 comments on commit 872500f

Please sign in to comment.