v2 #43
|
@ -0,0 +1,38 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"owl-blogs/app/repository"
|
||||
"owl-blogs/domain/model"
|
||||
)
|
||||
|
||||
type EntryService struct {
|
||||
EntryRepository repository.EntryRepository
|
||||
}
|
||||
|
||||
func NewEntryService(entryRepository repository.EntryRepository) *EntryService {
|
||||
return &EntryService{EntryRepository: entryRepository}
|
||||
}
|
||||
|
||||
func (s *EntryService) Create(entry model.Entry) error {
|
||||
return s.EntryRepository.Create(entry)
|
||||
}
|
||||
|
||||
func (s *EntryService) Update(entry model.Entry) error {
|
||||
return s.EntryRepository.Update(entry)
|
||||
}
|
||||
|
||||
func (s *EntryService) Delete(entry model.Entry) error {
|
||||
return s.EntryRepository.Delete(entry)
|
||||
}
|
||||
|
||||
func (s *EntryService) FindById(id string) (model.Entry, error) {
|
||||
return s.EntryRepository.FindById(id)
|
||||
}
|
||||
|
||||
func (s *EntryService) FindAllByType(types *[]string) ([]model.Entry, error) {
|
||||
return s.EntryRepository.FindAll(types)
|
||||
}
|
||||
|
||||
func (s *EntryService) FindAll() ([]model.Entry, error) {
|
||||
return s.EntryRepository.FindAll(nil)
|
||||
}
|
16
go.mod
16
go.mod
|
@ -3,11 +3,27 @@ module owl-blogs
|
|||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gofiber/fiber/v2 v2.47.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
||||
github.com/klauspost/compress v1.16.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||
github.com/stretchr/objx v0.5.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
github.com/tinylib/msgp v1.1.8 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.47.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
80
go.sum
80
go.sum
|
@ -1,15 +1,40 @@
|
|||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/gofiber/fiber/v2 v2.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs=
|
||||
github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
|
||||
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
|
||||
github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY=
|
||||
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||
|
@ -18,6 +43,61 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
||||
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c=
|
||||
github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package infra
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type SqliteDatabase struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
func NewSqliteDB(path string) Database {
|
||||
db := sqlx.MustOpen("sqlite3", path)
|
||||
return &SqliteDatabase{db: db}
|
||||
}
|
||||
|
||||
func (d *SqliteDatabase) Get() *sqlx.DB {
|
||||
return d.db
|
||||
}
|
31
main.go
31
main.go
|
@ -1,30 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"reflect"
|
||||
"owl-blogs/app"
|
||||
"owl-blogs/infra"
|
||||
"owl-blogs/web"
|
||||
)
|
||||
|
||||
func Persist(entry model.Entry) error {
|
||||
t := reflect.TypeOf(entry).Elem().Name()
|
||||
|
||||
fmt.Println(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
// repo := infra.NewEntryRepository()
|
||||
// repo.RegisterEntryType(&model.ImageEntry{})
|
||||
|
||||
// var img model.Entry = &model.ImageEntry{}
|
||||
// img.Create("id", "content", nil, &model.ImageEntryMetaData{ImagePath: "path"})
|
||||
|
||||
// repo.Save(img)
|
||||
|
||||
// img2, err := repo.FindById("id")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// fmt.Println(img2)
|
||||
db := infra.NewSqliteDB("owlblogs.db")
|
||||
repo := infra.NewEntryRepository(db)
|
||||
entryService := app.NewEntryService(repo)
|
||||
webApp := web.NewWebApp(entryService)
|
||||
webApp.Run()
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,56 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type WebApp struct {
|
||||
app *fiber.App
|
||||
entryService *app.EntryService
|
||||
}
|
||||
|
||||
func NewWebApp(entryService *app.EntryService) *WebApp {
|
||||
app := fiber.New()
|
||||
|
||||
indexHandler := NewIndexHandler(entryService)
|
||||
listHandler := NewListHandler(entryService)
|
||||
entryHandler := NewEntryHandler(entryService)
|
||||
mediaHandler := NewMediaHandler(entryService)
|
||||
rssHandler := NewRSSHandler(entryService)
|
||||
loginHandler := NewLoginHandler(entryService)
|
||||
editorHandler := NewEditorHandler(entryService)
|
||||
|
||||
// app.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
|
||||
app.Get("/", indexHandler.Handle)
|
||||
app.Get("/lists/:list/", listHandler.Handle)
|
||||
// Editor
|
||||
app.Get("/editor/auth/", loginHandler.HandleGet)
|
||||
app.Post("/editor/auth/", loginHandler.HandlePost)
|
||||
app.Get("/editor/", editorHandler.HandleGet)
|
||||
app.Post("/editor/", editorHandler.HandlePost)
|
||||
// Media
|
||||
app.Get("/media/*filepath", mediaHandler.Handle)
|
||||
// RSS
|
||||
app.Get("/index.xml", rssHandler.Handle)
|
||||
// Posts
|
||||
app.Get("/posts/:post/", entryHandler.Handle)
|
||||
app.Get("/posts/:post/media/*filepath", mediaHandler.Handle)
|
||||
// Webmention
|
||||
// app.Post("/webmention/", userWebmentionHandler(repo))
|
||||
// Micropub
|
||||
// app.Post("/micropub/", userMicropubHandler(repo))
|
||||
// IndieAuth
|
||||
// app.Get("/auth/", userAuthHandler(repo))
|
||||
// app.Post("/auth/", userAuthProfileHandler(repo))
|
||||
// app.Post("/auth/verify/", userAuthVerifyHandler(repo))
|
||||
// app.Post("/auth/token/", userAuthTokenHandler(repo))
|
||||
// app.Get("/.well-known/oauth-authorization-server", userAuthMetadataHandler(repo))
|
||||
// app.NotFound = http.HandlerFunc(notFoundHandler(repo))
|
||||
return &WebApp{app: app, entryService: entryService}
|
||||
}
|
||||
|
||||
func (w *WebApp) Run() {
|
||||
w.app.Listen(":3000")
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type EditorHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewEditorHandler(entryService *app.EntryService) *EditorHandler {
|
||||
return &EditorHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *EditorHandler) HandleGet(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Editor!")
|
||||
}
|
||||
|
||||
func (h *EditorHandler) HandlePost(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Editor!")
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type EntryHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewEntryHandler(entryService *app.EntryService) *EntryHandler {
|
||||
return &EntryHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *EntryHandler) Handle(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, RSS!")
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type IndexHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewIndexHandler(entryService *app.EntryService) *IndexHandler {
|
||||
return &IndexHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *IndexHandler) Handle(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, World 👋!")
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type ListHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewListHandler(entryService *app.EntryService) *ListHandler {
|
||||
return &ListHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *ListHandler) Handle(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, List!")
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type LoginHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewLoginHandler(entryService *app.EntryService) *LoginHandler {
|
||||
return &LoginHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *LoginHandler) HandleGet(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Login!")
|
||||
}
|
||||
|
||||
func (h *LoginHandler) HandlePost(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Login!")
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type MediaHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewMediaHandler(entryService *app.EntryService) *MediaHandler {
|
||||
return &MediaHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *MediaHandler) Handle(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Media!")
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"owl-blogs/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type RSSHandler struct {
|
||||
entrySvc *app.EntryService
|
||||
}
|
||||
|
||||
func NewRSSHandler(entryService *app.EntryService) *RSSHandler {
|
||||
return &RSSHandler{entrySvc: entryService}
|
||||
}
|
||||
|
||||
func (h *RSSHandler) Handle(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, RSS!")
|
||||
}
|
Loading…
Reference in New Issue