Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tạo file setting để thay thế cho biến môi trường #22

Open
hongquan opened this issue Dec 31, 2020 · 3 comments
Open

Tạo file setting để thay thế cho biến môi trường #22

hongquan opened this issue Dec 31, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@hongquan
Copy link

Thấy bạn đang dùng các biến môi trường làm settings.

source SETTINGS.env
export DOCBAO_EXPORT_TO_RABBITMQ=true
export DOCBAO_RABBITMQ_HOST=127.0.0.1
export DOCBAO_RABBITMQ_USERNAME='admin'
export DOCBAO_RABBITMQ_PASSWORD='password'
export DOCBAO_RABBITMQ_EXCHANGE='exchange_name'
export DOCBAO_RABBITMQ_DEFAULT_QUEUE='default_queue_name'

Điều này hơi kì khôi. Biến môi trường chỉ nên dùng một ít để overwrite settings thôi. Biến môi trường có hạn chế:

  • Giá trị của nó hoàn toàn là text. Nó không hỗ trợ kiểu dữ liệu đa dạng, dữ liệu đọc lên toàn bộ là text ("1", "true") dẫn tới bạn phải đặt ra luật riêng để "ép kiểu" từ text sang giá trị thực, ví dụ từ "1" thành integer, từ "true", "1", "yes" thành boolean.
  • Cách gán giá trị cho biến môi trường là đang theo cú pháp của shell, khiến bạn phải viết dính chùm, ví dụ USERNAME='admin', không thể viết cách cho thông thoáng, dễ nhìn USERNAME = admin.

Đề xuất giải pháp:

  • Dùng file TOML.

Ghi chú:

  • Có 1 loại file hay được nhắc đến nhiều hơn là YAML, nhưng so với TOML, YAML có điểm dở là không hỗ trợ kiểu boolean, nên
    người ta đặt ra một đống quy ước để biểu diễn giá trị boolean ("0", "1", "true", "false", "yes", "no", "t", "f"...)
  • Đừng dùng JSON vì file JSON không cho ghi comment.
@hailoc12
Copy link
Owner

hailoc12 commented Feb 1, 2021

Mình cũng băn khoăn là good practice thì nên xử lý setting như nào. Hiện mình dùng biến môi trường vì nghĩ rằng khi chuyển sang Docker sẽ dễ dàng hơn ?

@hailoc12 hailoc12 added the question Further information is requested label Feb 1, 2021
@hongquan
Copy link
Author

hongquan commented Feb 1, 2021

chuyển sang Docker sẽ dễ dàng hơn

chỉ dễ dàng hơn với một vài giá trị thôi, chứ như đã phân tích, biến môi trường bị hạn chế khoản phản ánh kiểu dữ liệu, nên nếu vấp phải vấn đề này thì chữ "dễ" sẽ biến thành "khó", chưa kể nếu số lượng setting lớn thì quản lý sẽ mệt (không thể gom tổ chức thành nhóm).

@hailoc12 hailoc12 added the help wanted Extra attention is needed label Feb 9, 2021
@hailoc12 hailoc12 changed the title Không nên dùng hoàn toàn biến môi trường làm settings Tạo file setting để thay thế cho biến môi trường Feb 9, 2021
@hailoc12
Copy link
Owner

hailoc12 commented Feb 9, 2021

Ukie, mình đã chuyển thành task trong backlog

@hailoc12 hailoc12 added the enhancement New feature or request label Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants