Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
<100 subscribers
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
MongoDB는 C++로 작성된 대표적인 NoSQL이다.
보통 AWS Document DB나 Mongo Atlas를 이용하곤하는데, 본 예제에서는 Mongo Atlas를 이용했다.
공식 문서에서는 Document oriented database라고 소개하고 있는데, 여기서 말하는 Document는 RDMS의 record와 비슷한 개념이다.
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"username": "velopert",
"name": { first: "M.J.", last: "Kim" }
}
위와 같은 json 형태의 데이터가 있다고 생각해보자.
실제로 MongoDB에 어떤 데이터를 저장하면 위와 같이 생성되는 것을 확인할 수 있다.
Document는 어떤 형태의 데이터를 문서로 보는 관점이라고 생각하면 좋을 것 같다.
Collection은 Document의 그룹이다. RDMS의 테이블과 비슷하다고 볼 수 있지만 조금 다른게, Document 자체는 동적인 schema를 가지고 있다. (schema가 없다)
간단하게 생각하면 다음과 같은 일이 가능하다.
Collection 1
{
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"username": "velopert",
"name": { first: "M.J.", last: "Kim" }
},
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"name": { first: "M.J.", last: "Kim" }
}
}
같은 Collection에서 각기 다른 json 스키마를 허용한다.
MongoDB Atlas에서 Database를 생성하고, 그 이후에 Collection을 생성할 수가 있는데, Database는 Collection들의 물리적인 컨테이너이다.
Mongo DB Atlas를 들어가보고 느낀건데, 정말 잘 되어있다.
코드 예제, 클러스터 생성부터 개발자 친화적으로 잘 만들어줬다는 생각이 들었다.
또한 Mongo Atlas를 이용해서 AWS에 서버리스 형태로 배포하더라도 Document DB를 쓰는 것 보다 요금이 싼 것 같다.
서버리스 형태로 AWS에 클러스터를 생성할 수 있었고, Go에서는 다음과 같이 연결할 수 있다.
package db
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"os"
)
func MongoURI() string {
return fmt.Sprintf("mongodb+srv://%s:%s@%s.subnw.mongodb.net/?retryWrites=true&w=majority",
os.Getenv("MONGODB_USERNAME"), os.Getenv("MONGODB_PASSWORD"), os.Getenv("MONGODB_CLUSTER"))
}
func MongoOpts() *options.ServerAPIOptions {
return options.ServerAPI(options.ServerAPIVersion1)
}
func NewMongoDB() *mongo.Client {
serverAPI := MongoOpts()
uri := MongoURI()
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
client, err := mongo.Connect(context.Background(), opts)
if err != nil {
panic(err)
}
return client
}
꽤나 단순하게 연결이 가능하다. 예제 코드는 전부 MongoDB Atlas에서 제공해준 코드이다.
ServerAPIVersion1이라는 코드를 보면 왜 버전1을 쓴거지? 라는 생각이 들 수 있지만 Version1밖에 없고 Stable이라고 하니 안심하고 써도 될 것 같다.
MongoDB는 C++로 작성된 대표적인 NoSQL이다.
보통 AWS Document DB나 Mongo Atlas를 이용하곤하는데, 본 예제에서는 Mongo Atlas를 이용했다.
공식 문서에서는 Document oriented database라고 소개하고 있는데, 여기서 말하는 Document는 RDMS의 record와 비슷한 개념이다.
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"username": "velopert",
"name": { first: "M.J.", last: "Kim" }
}
위와 같은 json 형태의 데이터가 있다고 생각해보자.
실제로 MongoDB에 어떤 데이터를 저장하면 위와 같이 생성되는 것을 확인할 수 있다.
Document는 어떤 형태의 데이터를 문서로 보는 관점이라고 생각하면 좋을 것 같다.
Collection은 Document의 그룹이다. RDMS의 테이블과 비슷하다고 볼 수 있지만 조금 다른게, Document 자체는 동적인 schema를 가지고 있다. (schema가 없다)
간단하게 생각하면 다음과 같은 일이 가능하다.
Collection 1
{
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"username": "velopert",
"name": { first: "M.J.", last: "Kim" }
},
{
"_id": ObjectId("5099803df3f4948bd2f98391"),
"name": { first: "M.J.", last: "Kim" }
}
}
같은 Collection에서 각기 다른 json 스키마를 허용한다.
MongoDB Atlas에서 Database를 생성하고, 그 이후에 Collection을 생성할 수가 있는데, Database는 Collection들의 물리적인 컨테이너이다.
Mongo DB Atlas를 들어가보고 느낀건데, 정말 잘 되어있다.
코드 예제, 클러스터 생성부터 개발자 친화적으로 잘 만들어줬다는 생각이 들었다.
또한 Mongo Atlas를 이용해서 AWS에 서버리스 형태로 배포하더라도 Document DB를 쓰는 것 보다 요금이 싼 것 같다.
서버리스 형태로 AWS에 클러스터를 생성할 수 있었고, Go에서는 다음과 같이 연결할 수 있다.
package db
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"os"
)
func MongoURI() string {
return fmt.Sprintf("mongodb+srv://%s:%s@%s.subnw.mongodb.net/?retryWrites=true&w=majority",
os.Getenv("MONGODB_USERNAME"), os.Getenv("MONGODB_PASSWORD"), os.Getenv("MONGODB_CLUSTER"))
}
func MongoOpts() *options.ServerAPIOptions {
return options.ServerAPI(options.ServerAPIVersion1)
}
func NewMongoDB() *mongo.Client {
serverAPI := MongoOpts()
uri := MongoURI()
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
client, err := mongo.Connect(context.Background(), opts)
if err != nil {
panic(err)
}
return client
}
꽤나 단순하게 연결이 가능하다. 예제 코드는 전부 MongoDB Atlas에서 제공해준 코드이다.
ServerAPIVersion1이라는 코드를 보면 왜 버전1을 쓴거지? 라는 생각이 들 수 있지만 Version1밖에 없고 Stable이라고 하니 안심하고 써도 될 것 같다.
No comments yet