From 87d631de7a22faf9d2a3acf0b5d540763baf1b64 Mon Sep 17 00:00:00 2001 From: sharin-sushi Date: Fri, 26 Jan 2024 10:44:11 +0900 Subject: [PATCH] =?UTF-8?q?api=E4=BD=9C=E6=88=90=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test0015Go/cmd/main.go | 23 +++++++++- test0015Go/domain/types.go | 63 ++++++++++++++++---------- test0015Go/go.mod | 21 +++++---- test0015Go/go.sum | 26 +++-------- test0015Go/sample/nodb_api/top_page.go | 55 ++++++++++++++++++++++ 5 files changed, 134 insertions(+), 54 deletions(-) create mode 100644 test0015Go/sample/nodb_api/top_page.go diff --git a/test0015Go/cmd/main.go b/test0015Go/cmd/main.go index 673bab0..887b298 100644 --- a/test0015Go/cmd/main.go +++ b/test0015Go/cmd/main.go @@ -1,8 +1,10 @@ package main import ( + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" "github.com/sharin-sushi/0015docker/sample" + "github.com/sharin-sushi/0015docker/sample/nodb_api" ) // "github.com/sharin-sushi/0015docker/sample" // 消えないようにメモ @@ -11,6 +13,17 @@ func main() { // pointer.go // for x, y := range のテスト r := gin.Default() + + r.Use(cors.New(cors.Config{ + AllowOrigins: []string{ + "http://localhost", "https://localhost", + "http://v-karaoke.com", + }, + AllowMethods: []string{"POST", "GET", "PUT", "DELETE"}, + AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Cookie"}, + AllowCredentials: true, + })) + rangeTest := r.Group("/range") { rangeTest.GET("/1", sample.Test1) @@ -18,6 +31,14 @@ func main() { rangeTest.GET("/2a", sample.Test2a) rangeTest.GET("/3", sample.Test3) } + ver := r.Group("/v1") + { + vcontents := ver.Group("/vcontents") + { + vcontents.GET("/", nodb_api.ReturnAlterTopPage) + } + } + // crypt.go AES化 // sample.AlterMainCrypt2() //元記事ほぼそのままのもの // sample.AlterMainCrypt() //自分用に改変したもの @@ -31,6 +52,6 @@ func main() { { typeTest.GET("/vt-slise", sample.AlterMainType) } - r.Run("localhost:8080") + r.Run(":8080") } diff --git a/test0015Go/domain/types.go b/test0015Go/domain/types.go index 3273516..c99b561 100644 --- a/test0015Go/domain/types.go +++ b/test0015Go/domain/types.go @@ -8,12 +8,11 @@ type Listener struct { } // VMK -type VtuberId int type Movie struct { - MovieUrl string `gorm:"primaryKey;type:varchar(100)"` //`json:"movie_url"` - MovieTitle *string `gorm:"type:varchar(200);not null"` //`json:"movie_title"` - VtuberId *VtuberId `gorm:"type:int(11);not null"` //`json:"vtuber_id"` - MovieInputterId *ListenerId `gorm:"type:int(11);not null"` //`json:"movie_inputter_id"` /new + MovieUrl string `gorm:"primaryKey;type:varchar(100)"` //`json:"movie_url"` + MovieTitle string `gorm:"type:varchar(200);not null"` //`json:"movie_title"` + VtuberId VtuberId `gorm:"type:int(11);not null"` //`json:"vtuber_id"` + MovieInputterId ListenerId `gorm:"type:int(11);not null"` //`json:"movie_inputter_id"` /new } // like_reration @@ -36,24 +35,40 @@ type FavoriteCountForContent struct { Count int `gorm:"type:int(11);default:0"` } -// Email string `gorm:"type:varchar(255);unique;not null"` -// Password string `gorm:"type:varchar(100);not null"` -// CreatedAt time.Time `gorm:"type:datetime;default:current_timestamp"` -// UpdatedAt sql.NullTime `gorm:"type:datetime"` -// DeletedAt gorm.DeletedAt `gorm:"type:datetime;index:deleted_index"` +type VtuberId int +type Vtuber struct { + VtuberId VtuberId `gorm:"primaryKey;type:int(11)"` //`json:"vtuber_id"` + VtuberName string `gorm:"type:varchar(50);not null;unique"` //`json:"vtuver_name"` + VtuberKana string `gorm:"type:varchar(50);unique"` //`json:"vtuber_kana"` + IntroMovieUrl string `gorm:"type:varchar(100)"` //`json:"vtuber_intro_movie_url"` + VtuberInputterId ListenerId `gorm:"type:int(11);not null"` //`json:"vtuber_inputter_id"` +} -// type KaraokeListId int -// type KaraokeList struct { -// MovieUrl string `gorm:"primaryKey;type:varchar(100)"` //`json:"movie_url"` -// KaraokeListId KaraokeListId `gorm:"primaryKey;type:int(11)"` //`json:"id"` -// SingStart *string `gorm:"type:time(0)"` //`json:"sing_start"` -// SongName string `gorm:"type:varchar(100)"` //`json:"song_name"` -// KaraokeListInputterId *ListenerId `gorm:"type:int(11)"` //`json:"inputter_id"` -// } +type TransmitMovie struct { + VtuberId + MovieUrl string + Vtuber + Movie + Count int + IsFav bool +} -// type Follow struct { -// Id int `gorm:"primaryKey;type:int(11)"` -// FollowListener int `gorm:"not null;type:int(11);uniqueIndex:follow_followed;not null"` -// FollowedVtuber int `gorm:"type:int(11);uniqueIndex:follow_followed"` -// FollowedListener int `gorm:"type:int(11);uniqueIndex:follow_followed"` -// } +type KaraokeId int +type Karaoke struct { + KaraokeId KaraokeId `gorm:"primaryKey;type:int(11);"` //`json:"id"` + MovieUrl string `gorm:"type:varchar(100);uniqueIndex:karaoke_uq:not null"` //`json:"movie_url"` + SingStart string `gorm:"type:time(0);uniqueIndex:karaoke_uq"` //`json:"sing_start"` + SongName string `gorm:"type:varchar(100)"` //`json:"song_name"` + KaraokeInputterId ListenerId `gorm:"type:int(11)"` //`json:"inputter_id"` +} + +type TransmitKaraoke struct { + VtuberId + Vtuber + MovieUrl string + Movie + KaraokeId + Karaoke + Count int + IsFav bool +} diff --git a/test0015Go/go.mod b/test0015Go/go.mod index 7fb8118..6ff2513 100644 --- a/test0015Go/go.mod +++ b/test0015Go/go.mod @@ -3,21 +3,27 @@ module github.com/sharin-sushi/0015docker go 1.18 require ( + github.com/gin-contrib/cors v1.5.0 github.com/gin-gonic/gin v1.9.1 gorm.io/gorm v1.25.4 ) -require github.com/go-sql-driver/mysql v1.7.0 // indirect - require ( - github.com/bytedance/sonic v1.10.2 // indirect + github.com/bytedance/sonic v1.10.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect - github.com/chenzhuoyu/iasm v0.9.1 // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect + github.com/go-playground/validator/v10 v10.15.5 // indirect + github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +require ( github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.16.0 // indirect github.com/goccy/go-json v0.10.2 // indirect // github.com/golang-jwt/jwt v3.2.2+incompatible github.com/jinzhu/inflection v1.0.0 // indirect @@ -25,13 +31,10 @@ require ( github.com/joho/godotenv v1.5.1 github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect - github.com/kr/pretty v0.3.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.6.0 // indirect @@ -40,7 +43,5 @@ require ( golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/mysql v1.5.2 ) diff --git a/test0015Go/go.sum b/test0015Go/go.sum index 68e3372..08da9ee 100644 --- a/test0015Go/go.sum +++ b/test0015Go/go.sum @@ -1,20 +1,21 @@ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= -github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= +github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= -github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= -github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 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/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/cors v1.5.0 h1:DgGKV7DDoOn36DFkNtbHrjoRiT5ExCe+PC9/xp7aKvk= +github.com/gin-contrib/cors v1.5.0/go.mod h1:TvU7MAZ3EwrPLI2ztzTt3tqgvBCq+wn8WpZmfADjupI= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= @@ -24,14 +25,12 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= -github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.15.5 h1:LEBecTWb/1j5TNY1YYG2RcOUN3R7NLylN+x8TTueE24= +github.com/go-playground/validator/v10 v10.15.5/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -48,12 +47,7 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= @@ -67,12 +61,9 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= 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/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= 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/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -107,10 +98,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 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= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test0015Go/sample/nodb_api/top_page.go b/test0015Go/sample/nodb_api/top_page.go new file mode 100644 index 0000000..7993e48 --- /dev/null +++ b/test0015Go/sample/nodb_api/top_page.go @@ -0,0 +1,55 @@ +package nodb_api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/sharin-sushi/0015docker/domain" +) + +func ReturnAlterTopPage(c *gin.Context) { + var errs []error + var allVts []domain.Vtuber + var VtsMosWithFav []domain.TransmitMovie + var VtsMosKasWithFav []domain.TransmitKaraoke + + allVts = []domain.Vtuber{ + { + VtuberId: 1, + VtuberName: "接続確認", + VtuberKana: "sucsessefuly_connect", + IntroMovieUrl: "", + VtuberInputterId: 1, + }, + } + + VtsMosWithFav = []domain.TransmitMovie{ + { + VtuberId: 1, + MovieUrl: "www.youtube.com/watch?v=4p1pIYBU61c", + Vtuber: domain.Vtuber{ + VtuberName: "接続確認", + VtuberKana: "sucsessefuly_connect", + IntroMovieUrl: "", + VtuberInputterId: 1, + }, + Movie: domain.Movie{ + MovieTitle: "牙アピールかわいいおいも[新人vTuber妹望おいも]", + VtuberId: 1, + MovieInputterId: 1, + }, + Count: 100, + IsFav: false, + }, + } + + c.JSON(http.StatusOK, gin.H{ + "vtubers": allVts, + "vtubers_movies": VtsMosWithFav, + "vtubers_movies_karaokes": VtsMosKasWithFav, + "error": errs, + "message": "dont you Loged in ?", + }) + return + +}