[关闭]
@zhongdao 2022-03-27T22:20:51.000000Z 字数 3247 阅读 780

golang 开发备忘录sql,module等

未分类


module路径相关

一、同一目录下多个文件共用一个包时

go run main.go api.go

二、同一目录多个包时

官方的module使用

https://go.dev/doc/tutorial/call-module-code

  1. <home>/
  2. |-- greetings/
  3. |-- hello/

go mod init example.com/greetings

数据库

sql

https://go.dev/doc/tutorial/database-access

提示:

  1. go run .
  2. [mysql] 2022/03/14 15:20:19 connector.go:95: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
  3. 2022/03/14 15:20:19 this user requires mysql native password authentication.
  4. exit status 1

解决办法:
https://www.icode9.com/content-2-1262929.html

gorm

Golang下的ORM框架gorm的介绍和使用
https://juejin.cn/post/6844904090196000775

vim

粘贴时正常

.vimrc

  1. let &t_SI .= "\<Esc>[?2004h"
  2. let &t_EI .= "\<Esc>[?2004l"
  3. inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
  4. function! XTermPasteBegin()
  5. set pastetoggle=<Esc>[201~
  6. set paste
  7. return ""
  8. endfunction

ngix 转发

Nginx入门教程
https://zhuanlan.zhihu.com/p/162773974

查看nginx的版本号
./nginx -v
启动nginx
./nginx
关闭nginx
./nginx -s stop
重新加载nginx

基本配置

根据请求后缀分发

  1. server {
  2. listen 7001;
  3. server_name 47.104.xxx.xxx;
  4. location ~ /dev/ {
  5. proxy_pass http://127.0.0.1:8080;
  6. }
  7. location ~ /prod/ {
  8. proxy_pass http://127.0.0.1:8081;
  9. }
  10. }

目前配置

/etc/nginx/sites-available/default

  1. server {
  2. # SSL configuration
  3. #
  4. # listen 443 ssl default_server;
  5. # listen [::]:443 ssl default_server;
  6. #
  7. # Note: You should disable gzip for SSL traffic.
  8. # See: https://bugs.debian.org/773332
  9. #
  10. # Read up on ssl_ciphers to ensure a secure configuration.
  11. # See: https://bugs.debian.org/765782
  12. #
  13. # Self signed certs generated by the ssl-cert package
  14. # Don't use them in a production server!
  15. #
  16. # include snippets/snakeoil.conf;
  17. #root /var/www/html;
  18. root /root/src/ttip-front-end/build;
  19. # Add index.php to the list if you are using PHP
  20. index index.html index.htm index.nginx-debian.html;
  21. server_name ttip.chinafilm-hualong.com; # managed by Certbot
  22. location / {
  23. # First attempt to serve request as file, then
  24. # as directory, then fall back to displaying a 404.
  25. #proxy_pass http://localhost:8888;
  26. try_files $uri $uri/ =404;
  27. }
  28. location /httpd {
  29. proxy_pass http://localhost:8999;
  30. }
  31. location /kdmplatform {
  32. proxy_pass http://localhost:18182;
  33. }
  34. location /operation {
  35. proxy_pass http://localhost:18183;
  36. }
  37. location /security {
  38. proxy_pass http://localhost:18184;
  39. }
  40. # pass PHP scripts to FastCGI server
  41. #
  42. #location ~ \.php$ {
  43. # include snippets/fastcgi-php.conf;
  44. #
  45. # # With php-fpm (or other unix sockets):
  46. # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  47. # # With php-cgi (or other tcp sockets):
  48. # fastcgi_pass 127.0.0.1:9000;
  49. #}
  50. # deny access to .htaccess files, if Apache's document root
  51. # concurs with nginx's one
  52. #
  53. #location ~ /\.ht {
  54. # deny all;
  55. #}
  56. listen [::]:443 ssl ipv6only=on; # managed by Certbot
  57. listen 443 ssl; # managed by Certbot
  58. ssl_certificate /etc/letsencrypt/live/ttip.chinafilm-hualong.com/fullchain.pem; # managed by Certbot
  59. ssl_certificate_key /etc/letsencrypt/live/ttip.chinafilm-hualong.com/privkey.pem; # managed by Certbot
  60. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  61. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  62. }
  63. server {
  64. if ($host = ttip.chinafilm-hualong.com) {
  65. return 301 https://$host$request_uri;
  66. } # managed by Certbot
  67. listen 80 ;
  68. listen [::]:80 ;
  69. server_name ttip.chinafilm-hualong.com;
  70. return 404; # managed by Certbot
  71. }

https证书申请

  1. sudo apt-get remove certbot
  2. sudo snap install --classic certbot
  3. #根据提示配置域名
  4. sudo certbot --nginx
  5. #追加域名
  6. certbot --expand -d yourdomain
  7. #生成独立的证书和私钥(不配置nginx),需要80端口不被占用
  8. certbot certonly --standalone --preferred-challenges http -d yourstandalonedomain
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注