python |
Pythonタグが付けられた新着投稿 - Qiita |
Unityゲームの手動デプロイで事故りまくったので自動化した話 |
https://qiita.com/Clpsplug/items/e4d8be4cf794bce547c1
|
unity |
2022-05-15 12:06:39 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
As a web engineer intern at ielove GROUP |
https://qiita.com/Kaitlyn_Summer/items/c43b89dbe9fcc7f09c1d
|
engine |
2022-05-15 12:40:41 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
Rubyで通信を伴うSPAを構築してみました |
https://qiita.com/keyasuda-2/items/96890a75a0072873e456
|
spasinglepageapplication |
2022-05-15 12:30:19 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
【mac】 docker + rails + mysql で環境構築 |
https://qiita.com/Kashitu/items/37be180df84486405e49
|
httpsww |
2022-05-15 12:17:28 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
【mac】 docker + rails + mysql で環境構築 |
https://qiita.com/Kashitu/items/37be180df84486405e49
|
httpsww |
2022-05-15 12:17:28 |
海外TECH |
DEV Community |
30 days of Leapfrog Student Partnership Program Learning Challenge. |
https://dev.to/aakas/30-days-of-leapfrog-student-partnership-program-learning-challenge-3o8k
|
days of Leapfrog Student Partnership Program Learning Challenge Actually the learning challenge is of days but I am writing this article as I have completed the halfway to challenge The challenge started on April The challenge is as a title defined to learn new or some thing related to the IT or tech stuff I was excited for the challenge and still am to complete it During the halfway to the challenge I learned about the SOLID principles design patterns Microservices UI design in figma read articles on blockchain cryptocurrency web and many more Also the challenge needed us to tweet the learning of the day I have been able to tweet everyday till halfway of the challenge and looking forward to complete without break twitter link aakash shakya |
2022-05-15 03:35:07 |
海外TECH |
DEV Community |
Go Echo API Server Development |
https://dev.to/nrikiji/go-echo-api-server-development-4008
|
Go Echo API Server DevelopmentCreate a simple api server based on a minimum configuration start project with the following functionsdb migration by sql migratedb operation from apps by gormInput check by go playground validatorSwitching of configuration files for each production and development environmentUser authentication middlewareAlso assume Firebase Authentication for user authentication and MySQL for database What we makeTwo APIs one to retrieve a list of blog posts and the other to update posted posts The API to list articles can be accessed by anyone and the API to update articles can only be accessed by the person who posted the article Prepare SetupClone the base project git clone Edit database connection information to match your environmentconfig ymldevelopment dialect mysql datasource root tcp localhost go echo example charset utfmb amp collation utfmb general ci amp parseTime true dir migrations table migrations posts table creation sql migrate config config yml create posts vi migrations xxxxxxx create posts sql migrate UpCREATE TABLE posts id bigint unsigned NOT NULL AUTO INCREMENT user id bigint unsigned NOT NULL title varchar COLLATE utfmb unicode ci NOT NULL body text COLLATE utfmb unicode ci NOT NULL PRIMARY KEY id FOREIGN KEY user id REFERENCES users id ENGINE InnoDB DEFAULT CHARSET utfmb COLLATE utfmb unicode ci sql migrate up env development config config yml sql migrate up env test config config ymlAlso the migration file for the users table is included in the base project simple table with only id name and firebase uid Register dummy dataCreate a user with email address password authentication from the firebase console and obtain an API key for the web Web API key in Project Settings gt General Also add the private key for using Firebase Admin SDK Firebase Admin SDK in Project Settings gt Service Account to the root of the project In this case the file name is firebase secret key json Obtain the localId Firebase user ID and idToken of the registered user from the API localId is set in users firebase uid and idToken is set in the http header when requesting the API This time request directly to firebase login API to get idToken and localId curl signInWithPassword key APIキー h Content Type application json d email foo example com password password returnSecureToken true jq localId xxxxxxxxxxxxxxx idToken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Register a user in DB with the obtained localId insert into users id firebase uid name created at updated at values xxxxxxxxxxxxxxx user now now insert into posts user id title body created at updated at values title body now now title body now now Now we are ready for development Implement the data manipulation partPrepare a model that represents records retrieved from DB model post gopackage modeltype Post struct ID uint gorm primaryKey json id UserID uint json user id User User json user Title string json title Body string json body Use gorm to add methods to the store to retrieve from and update the DB Since we have a UserStore in the base project we add the AllPosts and UpdatePost methods to it this timestore post gopackage storeimport errors go echo starter model gorm io gorm func us UserStore AllPosts model Post error var p model Post err us db Preload User Find amp p Error if err nil if errors Is err gorm ErrRecordNotFound return p nil return nil err return p nil func us UserStore UpdatePost post model Post error return us db Model post Updates post Error Implementing the acquisition APIImplement the part that acquires the model from the store and returns the response in json when requested Implementationhandler post gopackage handlerImport go echo starter model net http net http github com labstack echo v type postsResponse struct type postsResponse struct posts model Post json posts func h Handler getPosts c echo Context error posts err h userStore AllPosts if err nil return err return c JSON http StatusOK postsResponse Posts posts Call the handler when a GET request is made with a path named posts in a routehandler routes gopackage handlerImport go echo starter middleware github com labstack echo v func h Handler Register api echo Group api GET posts h getPosts Check operation go run server go curl http localhost api posts jq posts id user id user id name user title title body body title title body body write testPrepare two test data with fixturesfixtures posts yml id user id title Title body Body id user id title Title body Body Write tests for the handler Here we test that there is no error and that the number of items matches handler post test gopackage handlerimport encoding json net http net http httptest testing github com labstack echo v github com stretchr testify assert func TestGetPosts t testing T setup req httptest NewRequest echo GET api posts nil rec httptest NewRecorder c e NewContext req rec assert NoError t h getPosts c if assert Equal t http StatusOK rec Code var res postsResponse err json Unmarshal rec Body Bytes amp res assert NoError t err assert Equal t len res Posts Run a test cd handler go test run TestGetPosts ok go echo starter handler s Implement update APIApply auth middleware for authentication to prevent others from updating their posts What this middleware does is to get the firebase user id from the firebase idToken set in the http header Authorization Bearer xxxxx search the users table using the UID as a key and set the result in The result is set in context In the handler if the user can be retrieved from the context authentication succeeds if not authentication fails user context Get user if user nil authentication fails else authentication succeeded Implementationhandler post gotype postResponse struct type postResponse struct post model Post json post type updatePostRequest struct type updatePostRequest title string json title validate required body string json body validate required func h Handler updatePost c echo Context error get user information get user information u c Get user if u nil return c JSON http StatusForbidden nil user u model User get article id strconv Atoi c Param id post err h userStore FindPostByID id if err nil return c JSON http StatusInternalServerError nil else if post nil return c JSON http StatusNotFound nil if it is someone else s post consider it as unauthorized access if post UserID user ID if post UserID user ID if post UserID return c JSON http StatusForbidden nil params amp updatePostRequest if err c Bind params err nil return c JSON http StatusInternalServerError nil Validation if err c Validate params err nil if err c Validate params err return c JSON http StatusBadRequest ae NewValidationError err ae ValidationMessages Title required Please enter a title Body required Please enter a body Update data post Title params Post Body params Body if err h userStore UpdatePost post err nil return c JSON http StatusInternalServerError nil return c JSON http StatusOK postResponse Post post Validation can be done using go playground validator s functionality which allows you to display default multilingual display of error messages However this app does not use it but instead defines a map keyed by field name and validation rule name and uses display fixed messages if err c Validate params err nil return c JSON http StatusBadRequest ae NewValidationError err ae ValidationMessages Title required required Title Body required required Body Next call the handler you created when a PATCH request is made in routes with the path postshandler routes gofunc h Handler Register api echo Group Auth middleware AuthMiddleware h authStore h userStore api PATCH posts id h updatePost auth Confirmation of operationPut the firebase idToken obtained above in the http header and check the operation go run server go curl X PATCH H Content Type application json frz H Authorization Bearer xxxxxxxxxxxxxx curl d title NewTitle body NewBody http localhost api posts jq post id title NewTitle body NewBody Checking for errors when trying to update someone else s article curl X PATCH H Content Type application json H Authorization Bearer xxxxxxxxxxxxxx d title NewTitle body NewBody http localhost api posts v HTTP Forbidden Writing TestsHandler tests that you can update your own articles but not others Update your own articlehandler post test gofunc TestUpdatePostSuccess t testing T setup reqJSON title NewTitle body NewBody authMiddleware middleware AuthMiddleware h authStore h userStore req httptest NewRequest echo PATCH api posts id strings NewReader reqJSON req Header Set echo HeaderContentType echo MIMEApplicationJSON req Header Set echo HeaderAuthorization Bearer ValidToken rec httptest NewRecorder c e NewContext req rec c SetPath api posts id c SetParamNames id c SetParamValues err authMiddleware func c echo Context error return h updatePost c c assert NoError t err if assert Equal t http StatusOK rec Code var res postResponse err json Unmarshal rec Body Bytes amp res assert NoError t err assert Equal t NewTitle res Post Title assert Equal t NewBody res Post Body test returns a fixed user id by idToken for the conversion of idToken to Firebase user id which is done by the authentication middleware Use the mock method prepared in base project func f fakeAuthClient VerifyIDToken context context Context token string auth Token error var uid string if token ValidToken uid ValidUID return amp auth Token UID uid nil else if token ValidToken uid ValidUID return amp auth Token UID uid nil else return nil errors New Invalid Token Trying to update someone else s article handler post test gofunc TestUpdatePostForbidden t testing T setup reqJSON title NewTitle body NewBody authMiddleware middleware AuthMiddleware h authStore h userStore req httptest NewRequest echo PATCH api posts id strings NewReader reqJSON req Header Set echo HeaderContentType echo MIMEApplicationJSON req Header Set echo HeaderAuthorization Bearer ValidToken rec httptest NewRecorder c e NewContext req rec c SetPath api posts id c SetParamNames id c SetParamValues err authMiddleware func c echo Context error return h updatePost c c assert NoError t err assert Equal t http StatusForbidden rec Code test run go test run TestUpdatePostSuccess・・・ok go echo starter handler s go test run TestUpdatePostForbidden・・・ok go echo starter handler s ConclusionSample we made this time |
2022-05-15 03:11:29 |
海外ニュース |
Japan Times latest articles |
China’s top military body may find itself in crosshairs of Japan counterstrike capability |
https://www.japantimes.co.jp/news/2022/05/15/national/politics-diplomacy/chinas-top-military-body-may-find-crosshairs-japan-counterstrike-capability/
|
China s top military body may find itself in crosshairs of Japan counterstrike capabilityThe proposed capability could cover command centers ordering missile attacks including China s Central Military Commission the highest decision making body of the country s armed forces |
2022-05-15 12:36:04 |
海外ニュース |
Japan Times latest articles |
Dollar’s strength pushes world economy deeper into slowdown |
https://www.japantimes.co.jp/news/2022/05/15/business/economy-business/dollar-strength/
|
Dollar s strength pushes world economy deeper into slowdownThe soaring dollar is propelling the global economy deeper into a synchronized slowdown by driving up borrowing costs and stoking financial market volatility |
2022-05-15 12:25:13 |
海外ニュース |
Japan Times latest articles |
NBA playoff exit leaves young Grizzlies ‘motivated’ for more |
https://www.japantimes.co.jp/sports/2022/05/15/basketball/nba/grizzlies-playoff-exit/
|
NBA playoff exit leaves young Grizzlies motivated for moreDillon Brooks vowed the franchise that won regular season games to earn the second seed in the Western Conference would especially have the Warriors in |
2022-05-15 12:36:22 |
北海道 |
北海道新聞 |
春の高校野球支部予選・5月15日の試合結果 |
https://www.hokkaido-np.co.jp/article/680959/
|
春の高校野球 |
2022-05-15 12:08:10 |
ビジネス |
東洋経済オンライン |
漫画「キングダム」(第26話)城壁を破る秘策 壮大な物語の序章「30話」を一挙公開! | キングダム | 東洋経済オンライン |
https://toyokeizai.net/articles/-/581165?utm_source=rss&utm_medium=http&utm_campaign=link_back
|
春秋戦国時代 |
2022-05-15 12:30:00 |
仮想通貨 |
BITPRESS(ビットプレス) |
[日経] ビットコインは老後資産か 米で論争に |
https://bitpress.jp/count2/3_9_13208
|
資産 |
2022-05-15 12:03:55 |
海外TECH |
reddit |
Ohtani goes opposite field for his 100th MLB home run to make it 7-1 for the Angels! |
https://www.reddit.com/r/baseball/comments/upwslq/ohtani_goes_opposite_field_for_his_100th_mlb_home/
|
Ohtani goes opposite field for his th MLB home run to make it for the Angels submitted by u Blazingbee to r baseball link comments |
2022-05-15 03:02:36 |
コメント
コメントを投稿