본문 바로가기

분류 전체보기26

@property와 __call__ 비교 class Calculate: def __init__(self): self.result = 3 @property def one_plus_two(self) -> int: """ 일급 객체와는 다르다. 일급 객체는 변수 할당, 함수 인자 전달, 함수의 리턴 값이 될 수 있는 특징이 있기 때문이다. """ return self.resultif __name__ == "__main__": cal = Calculate() print(cal) # print(type(cal)) # # print(cal()) # 'Calculate' object is not callable 예외 print(c.. 2024. 5. 8.
Python structlog Standard Library LoggingIdeally, structlog should be able to be used as a drop-in replacement for standard library’s logging by wrapping it. In other words, you should be able to replace your call to logging.getLogger() b...www.structlog.org이전 글에서 작성했던 파이썬 내장 라이브러리 logging으로 구현했던 것을 structlog로 구현할 수 있다. Python logging파이썬에서도 날짜 별로, 특정 주기마다 로그 파일을 자동으로 생성할 수 있다.(trace Id도 설정하면 좋으련만...)구글링을 하면서 정리한.. 2024. 5. 3.
Middleware 커스텀해서 사용하기 from fastapi import FastAPIfrom middlewares import CustomMiddlewareapp = FastAPI()app.add_middleware(CustomMiddleware) # 미들웨어 추가middlewares.pyfrom starlette.types import ASGIApp, Receive, Scope, Sendclass CustomMiddleware: def __init__(self, app: ASGIApp) -> None: self.app = app async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: # do something await.. 2024. 5. 3.
Github Action & 도커 허브에 이미지 전송 name: action nameon: push: branches: - mainjobs: build: runs-on: ubuntu-latest steps: - name: Login to Dockerhub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - uses: actions/checkout@v3 - run: docker build -t ${{ secrets.DOCKER_USERNAME }}/server-test -f ./server.. 2024. 5. 1.