Skip to content

Commit 872500f

Browse files
committed
updated code for latest Go version
1 parent c892d26 commit 872500f

20 files changed

+124
-127
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:22.04
22

33
#RUN sudo apt-get update
44
RUN apt-get update

data/contentStore/home.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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}
1+
{"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}

handlers/adminBackupHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handlers
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
)
77

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

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

90-
bkdata, rferr := ioutil.ReadAll(file)
90+
bkdata, rferr := io.ReadAll(file)
9191
h.Log.Debug("read file err: ", rferr)
9292

9393
h.Log.Debug("handler.Filename: ", handler.Filename)

handlers/adminImageHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handlers
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66

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

44-
data, rferr := ioutil.ReadAll(file)
44+
data, rferr := io.ReadAll(file)
4545
h.Log.Debug("read file err: ", rferr)
4646

4747
h.Log.Debug("handler.Filename: ", handler.Filename)

handlers/adminTemplateHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handlers
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
"strings"
77

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

63-
data, rferr := ioutil.ReadAll(tfile)
63+
data, rferr := io.ReadAll(tfile)
6464
h.Log.Debug("read file err: ", rferr)
6565

6666
i := strings.Index(handler.Filename, ".")

handlers/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestCmsHandler_ProcessBody(t *testing.T) {
3434
robj.Valid = true
3535
robj.Code = "3"
3636
// var res http.Response
37-
// res.Body = ioutil.NopCloser(bytes.NewBufferString(`{"valid":true, "code":"1"}`))
37+
// res.Body = io.NopCloser(bytes.NewBufferString(`{"valid":true, "code":"1"}`))
3838
var sURL = "http://localhost/test"
3939
aJSON, _ := json.Marshal(robj)
4040
r, _ := http.NewRequest("POST", sURL, bytes.NewBuffer(aJSON))

handlers/loggingHandler_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"bytes"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"log"
1010
"net/http"
1111
"net/http/httptest"
@@ -22,7 +22,7 @@ func TestCmsHandler_SetLogLevel(t *testing.T) {
2222
oh.Log = &logger
2323

2424
h := oh.GetNew()
25-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
25+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`))
2626
//aJSON, _ := json.Marshal(robj)
2727
//fmt.Println("aJSON: ", aJSON)
2828
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -32,7 +32,7 @@ func TestCmsHandler_SetLogLevel(t *testing.T) {
3232
w := httptest.NewRecorder()
3333
h.SetLogLevel(w, r)
3434
resp := w.Result()
35-
body, _ := ioutil.ReadAll(resp.Body)
35+
body, _ := io.ReadAll(resp.Body)
3636
var lres LogResponse
3737
json.Unmarshal(body, &lres)
3838
fmt.Println("body: ", string(body))
@@ -48,7 +48,7 @@ func TestCmsHandler_SetLogLevelBadReq(t *testing.T) {
4848
oh.Log = &logger
4949

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

7676
h := oh.GetNew()
77-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"info"}`))
77+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"info"}`))
7878
//aJSON, _ := json.Marshal(robj)
7979
//fmt.Println("aJSON: ", aJSON)
8080
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -84,7 +84,7 @@ func TestCmsHandler_SetInfoLogLevel(t *testing.T) {
8484
w := httptest.NewRecorder()
8585
h.SetLogLevel(w, r)
8686
resp := w.Result()
87-
body, _ := ioutil.ReadAll(resp.Body)
87+
body, _ := io.ReadAll(resp.Body)
8888
var lres LogResponse
8989
json.Unmarshal(body, &lres)
9090
fmt.Println("body: ", string(body))
@@ -100,7 +100,7 @@ func TestCmsHandler_SetAllLogLevel(t *testing.T) {
100100
oh.Log = &logger
101101

102102
h := oh.GetNew()
103-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"all"}`))
103+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"all"}`))
104104
//aJSON, _ := json.Marshal(robj)
105105
//fmt.Println("aJSON: ", aJSON)
106106
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -110,7 +110,7 @@ func TestCmsHandler_SetAllLogLevel(t *testing.T) {
110110
w := httptest.NewRecorder()
111111
h.SetLogLevel(w, r)
112112
resp := w.Result()
113-
body, _ := ioutil.ReadAll(resp.Body)
113+
body, _ := io.ReadAll(resp.Body)
114114
var lres LogResponse
115115
json.Unmarshal(body, &lres)
116116
fmt.Println("body: ", string(body))
@@ -126,7 +126,7 @@ func TestCmsHandler_SetOffLogLevel(t *testing.T) {
126126
oh.Log = &logger
127127

128128
h := oh.GetNew()
129-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
129+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
130130
//aJSON, _ := json.Marshal(robj)
131131
//fmt.Println("aJSON: ", aJSON)
132132
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -136,7 +136,7 @@ func TestCmsHandler_SetOffLogLevel(t *testing.T) {
136136
w := httptest.NewRecorder()
137137
h.SetLogLevel(w, r)
138138
resp := w.Result()
139-
body, _ := ioutil.ReadAll(resp.Body)
139+
body, _ := io.ReadAll(resp.Body)
140140
var lres LogResponse
141141
json.Unmarshal(body, &lres)
142142
fmt.Println("body: ", string(body))
@@ -153,7 +153,7 @@ func TestCmsHandler_SetOffLogLevelLogKey(t *testing.T) {
153153
oh.Log = &logger
154154

155155
h := oh.GetNew()
156-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
156+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
157157
//aJSON, _ := json.Marshal(robj)
158158
//fmt.Println("aJSON: ", aJSON)
159159
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -163,7 +163,7 @@ func TestCmsHandler_SetOffLogLevelLogKey(t *testing.T) {
163163
w := httptest.NewRecorder()
164164
h.SetLogLevel(w, r)
165165
resp := w.Result()
166-
body, _ := ioutil.ReadAll(resp.Body)
166+
body, _ := io.ReadAll(resp.Body)
167167
var lres LogResponse
168168
json.Unmarshal(body, &lres)
169169
fmt.Println("body: ", string(body))
@@ -181,7 +181,7 @@ func TestCmsHandler_SetOffLogLevelLogWrongKey(t *testing.T) {
181181
oh.Log = &logger
182182

183183
h := oh.GetNew()
184-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
184+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
185185
//aJSON, _ := json.Marshal(robj)
186186
//fmt.Println("aJSON: ", aJSON)
187187
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -191,7 +191,7 @@ func TestCmsHandler_SetOffLogLevelLogWrongKey(t *testing.T) {
191191
w := httptest.NewRecorder()
192192
h.SetLogLevel(w, r)
193193
resp := w.Result()
194-
body, _ := ioutil.ReadAll(resp.Body)
194+
body, _ := io.ReadAll(resp.Body)
195195
var lres LogResponse
196196
json.Unmarshal(body, &lres)
197197
fmt.Println("body: ", string(body))
@@ -217,7 +217,7 @@ func TestCmsHandler_SetOffLogLevelBadMedia(t *testing.T) {
217217
oh.Log = &logger
218218

219219
h := oh.GetNew()
220-
aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
220+
aJSON := io.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`))
221221
//aJSON, _ := json.Marshal(robj)
222222
//fmt.Println("aJSON: ", aJSON)
223223
r, _ := http.NewRequest("POST", "/ffllist", aJSON)
@@ -227,7 +227,7 @@ func TestCmsHandler_SetOffLogLevelBadMedia(t *testing.T) {
227227
w := httptest.NewRecorder()
228228
h.SetLogLevel(w, r)
229229
resp := w.Result()
230-
body, _ := ioutil.ReadAll(resp.Body)
230+
body, _ := io.ReadAll(resp.Body)
231231
var lres LogResponse
232232
json.Unmarshal(body, &lres)
233233
fmt.Println("body: ", string(body))

main

-2.37 KB
Binary file not shown.

services/backupService.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"compress/zlib"
99
"encoding/json"
1010
"io"
11-
"io/ioutil"
1211
"os"
1312
"path/filepath"
1413
)
@@ -20,22 +19,22 @@ const (
2019
templateFiles = "templateFiles"
2120
)
2221

23-
//BackupFiles BackupFiles
22+
// BackupFiles BackupFiles
2423
type BackupFiles struct {
2524
ContentStoreFiles *[]BackupFile
2625
TemplateStoreFiles *[]BackupFile
2726
ImageFiles *[]BackupFile
2827
TemplateFiles *BackupFile
2928
}
3029

31-
//BackupFile BackupFile
30+
// BackupFile BackupFile
3231
type BackupFile struct {
3332
FilesLocation string
3433
Name string
3534
FileData []byte
3635
}
3736

38-
//UploadBackups UploadBackups
37+
// UploadBackups UploadBackups
3938
func (c *CmsService) UploadBackups(bk *[]byte) bool {
4039
var rtn bool
4140
var bkfs BackupFiles
@@ -59,7 +58,7 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
5958
for _, cf := range *bkfs.ContentStoreFiles {
6059
c.Log.Debug("BackupFile content file name: ", c.ContentStorePath+string(filepath.Separator)+cf.Name)
6160
c.Log.Debug("BackupFile content file: ", cf)
62-
werr := ioutil.WriteFile(c.ContentStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
61+
werr := os.WriteFile(c.ContentStorePath+string(filepath.Separator)+cf.Name, cf.FileData, 0666)
6362
c.Log.Debug("BackupFile content file write err : ", werr)
6463
}
6564

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

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

@@ -114,19 +113,19 @@ func (c *CmsService) UploadBackups(bk *[]byte) bool {
114113
return rtn
115114
}
116115

117-
//DownloadBackups DownloadBackups
116+
// DownloadBackups DownloadBackups
118117
func (c *CmsService) DownloadBackups() (bool, *[]byte) {
119118
var rtn bool
120119
var bkfs BackupFiles
121120

122121
//contentStore
123122
var contStoreFiles []BackupFile
124-
cntfiles, err := ioutil.ReadDir(c.ContentStorePath)
123+
cntfiles, err := os.ReadDir(c.ContentStorePath)
125124
if err == nil {
126125
for _, sfile := range cntfiles {
127126
if !sfile.IsDir() {
128127
c.Log.Debug("content store file: ", c.ContentStorePath+string(filepath.Separator)+sfile.Name())
129-
fileData, rerr := ioutil.ReadFile(c.ContentStorePath + string(filepath.Separator) + sfile.Name())
128+
fileData, rerr := os.ReadFile(c.ContentStorePath + string(filepath.Separator) + sfile.Name())
130129
//c.Log.Debug("content store file data: ", fileData)
131130
if rerr == nil {
132131
var cbk BackupFile
@@ -143,12 +142,12 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {
143142

144143
//templateStore
145144
var templateStoreFiles []BackupFile
146-
tempfiles, err := ioutil.ReadDir(c.TemplateStorePath)
145+
tempfiles, err := os.ReadDir(c.TemplateStorePath)
147146
if err == nil {
148147
for _, sfile := range tempfiles {
149148
if !sfile.IsDir() {
150149
c.Log.Debug("template store file: ", c.TemplateStorePath+string(filepath.Separator)+sfile.Name())
151-
fileData, rerr := ioutil.ReadFile(c.TemplateStorePath + string(filepath.Separator) + sfile.Name())
150+
fileData, rerr := os.ReadFile(c.TemplateStorePath + string(filepath.Separator) + sfile.Name())
152151
c.Log.Debug("template store file data: ", fileData)
153152
if rerr == nil {
154153
var cbk BackupFile
@@ -165,13 +164,13 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {
165164

166165
//images
167166
var imageFiles []BackupFile
168-
imgfiles, err := ioutil.ReadDir(c.ImagePath)
167+
imgfiles, err := os.ReadDir(c.ImagePath)
169168
if err == nil {
170169
c.Log.Debug("imgfiles: ", imgfiles)
171170
for _, sfile := range imgfiles {
172171
if !sfile.IsDir() {
173172
c.Log.Debug("image file: ", c.ImagePath+string(filepath.Separator)+sfile.Name())
174-
fileData, rerr := ioutil.ReadFile(c.ImagePath + string(filepath.Separator) + sfile.Name())
173+
fileData, rerr := os.ReadFile(c.ImagePath + string(filepath.Separator) + sfile.Name())
175174
if rerr == nil {
176175
var cbk BackupFile
177176
cbk.Name = sfile.Name()
@@ -190,7 +189,7 @@ func (c *CmsService) DownloadBackups() (bool, *[]byte) {
190189
var buf bytes.Buffer
191190
zr := gzip.NewWriter(&buf)
192191
tw := tar.NewWriter(zr)
193-
files, err := ioutil.ReadDir(c.TemplateFilePath)
192+
files, err := os.ReadDir(c.TemplateFilePath)
194193
if err == nil {
195194
for _, file := range files {
196195
if file.IsDir() {

services/backupService_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"compress/zlib"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"testing"
1110

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

4443
func TestCmsService_UploadBackups(t *testing.T) {
4544

46-
fileData, rerr := ioutil.ReadFile("./testBackupZips/compress.dat")
45+
fileData, rerr := os.ReadFile("./testBackupZips/compress.dat")
4746
fmt.Println(rerr)
4847

4948
var b bytes.Buffer
@@ -54,7 +53,7 @@ func TestCmsService_UploadBackups(t *testing.T) {
5453
io.Copy(&out, r)
5554
r.Close()
5655
rtn := out.Bytes()
57-
ioutil.WriteFile("./testBackupZips/uncompress.json", rtn, 0644)
56+
os.WriteFile("./testBackupZips/uncompress.json", rtn, 0644)
5857
}
5958
var cs CmsService
6059
cs.ContentStorePath = "./testBackupRestore/contentStore"

0 commit comments

Comments
 (0)