Daniel-Handsome
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    https://www.youtube.com/watch?v=MYmPY1E17ZM&t=7s https://pjchender.dev/golang/grpc-getting-started/#grpc-%E7%9A%84%E5%9B%9B%E7%A8%AE%E9%A1%9E%E5%9E%8B https://github.com/jincheng9/go-tutorial/tree/main/workspace/rpc/02 https://zhuanlan.zhihu.com/p/436041011 ## interceptor https://pandaychen.github.io/2020/02/25/GRPC-INTERCEPTOR-ALLINONE/ ## server 如何用遮罩跟 https://github.com/lubanproj/grpc-read/blob/master/8-grpc%20%E8%AE%A4%E8%AF%81%E9%89%B4%E6%9D%83%E2%80%94%E2%80%94oauth2%E8%AE%A4%E8%AF%81.md ## fieldmask https://loesspie.com/2021/12/24/protobuf-fieldmask/ ## grpc balance 对于高流量、信任客户端的场景,推荐使用客户端侧负载均衡,可以结合ZooKeeper、Etcd、Consul或Eureka使用。 对于需要服务器与客户端之间有信任边界的传统设置,推荐使用代理负载均衡,可以使用GCLB、haproxy或Envoy等。 对于微服务架构,特别是性能要求极高的场景(低延迟、高流量),且客户端可能不被信任,推荐使用旁路负载均衡。 https://colobu.com/2017/03/25/grpc-naming-and-load-balance/ https://www.lixueduan.com/posts/grpc/12-client-side-loadbalance/ https://pandaychen.github.io/2019/11/22/GRPC-BALANCER-DEEP-ANALYSIS/ https://pandaychen.github.io/2019/07/11/GRPC-SERVICE-DISCOVERY/ https://jerryzhou343.github.io/post/grpc_client_balancer/ 長連線處裡 https://pandaychen.github.io/2020/09/01/GRPC-CLIENT-CONN-LASTING/ grpc + k8s https://william-yeh.net/post/2020/03/grpc-load-balancing/ https://www.cnblogs.com/sunsky303/p/11119300.html ## picker https://pandaychen.github.io/2020/01/03/GRPC-PICKER-DEEP-ANALYSIS/ ## Prometheus https://pandaychen.github.io/2020/05/01/GRPC-PROMETHEUS-APP1/ ## go-grpc-middleware https://pandaychen.github.io/2020/02/25/GRPC-INTERCEPTOR-ALLINONE/ ## Metadata https://pandaychen.github.io/2020/02/04/GRPC-IMPROVEMENT/ ## Resolver https://pandaychen.github.io/2020/01/03/GRPC-RESOLVER-DEEP-ANALYSIS2-IN-KRATOS/ ## keepalive https://pandaychen.github.io/2020/09/01/GRPC-CLIENT-CONN-LASTING/ GRPC 断线重连可以通过以下方法实现: 设置通道选项:使用 "grpc.WithBackoffMaxDelay" 和 "grpc.WithBackoffMaxTimeout" 通道选项可以控制重试间隔和超时时间。 客户端重试:在客户端代码中,对调用失败的请求进行重试。 服务端心跳:客户端定期发送心跳请求,服务端检测到心跳请求的丢失,可以关闭连接。 ![image](https://hackmd.io/_uploads/Bk3Idbro6.png) ## grpc pool https://pandaychen.github.io/2020/10/03/DO-WE-NEED-GRPC-CLIENT-POOL/ ### k8s https://william-yeh.net/post/2020/03/grpc-load-balancing/ ## 健康检查 https://github.com/grpc/grpc-go/blob/master/examples/features/health/README.md health應該是客戶端要確認而已 server這邊起不來就掛了 不用確認 他只要set到對應的etcd就好 client那邊如果連不到就會跑backoff 去re connection 那如果單一個rpc (steam)有問題才會跑retrypolicy ## OpenTracing https://pandaychen.github.io/2020/06/01/GOLANG-TRACING-WITH-ZIPKIN/ ## pool https://pandaychen.github.io/2020/10/03/DO-WE-NEED-GRPC-CLIENT-POOL/ ## grpc-go https://juejin.cn/post/7230242762951983159 https://juejin.cn/post/7232483262979719205 https://zhuanlan.zhihu.com/p/623998314 ## retry ![image](https://hackmd.io/_uploads/BJ41M1Uca.png) 通道狀態主要關於客戶端與服務器之間的連接狀態。 RPC錯誤碼則是關於單個RPC調用的成功或失敗的具體原因 ![image](https://hackmd.io/_uploads/H1HDfy85a.png) ![image](https://hackmd.io/_uploads/rkJJSyUc6.png) 客户端角色:在gRPC架构中,客户端负责发起RPC调用,处理可能的网络问题,以及实现复杂的重试逻辑。WaitForReady和WithBackoff正是为了增强客户端在处理这些问题时的能力和灵活性。 服务端角色:而服务端的角色通常集中在处理接收到的RPC请求,执行业务逻辑,以及返回响应。服务端通常不直接涉及调用的重试逻辑,这部分由客户端负责。 服務跟server都要對應的timeout ![image](https://hackmd.io/_uploads/S1zRIy856.png) ### timeout ![image](https://hackmd.io/_uploads/r1eG9J89a.png) ![image](https://hackmd.io/_uploads/H1pXq185a.png) ## error https://medium.com/onedegree-tech-blog/%E8%AE%93%E9%8C%AF%E8%AA%A4%E6%88%90%E7%82%BA%E8%B3%87%E6%BA%90-grpc-%E7%9A%84%E9%8C%AF%E8%AA%A4%E8%99%95%E7%90%86%E6%A8%A1%E5%9E%8B-52e743e258bc ## proto特殊寫法 customer option 欄位可以空, 字不要太長 限制1~10之類的 比較算是自定義 ![](https://hackmd.io/_uploads/ryVGwqNih.png) import descriptor 這個套件 ![](https://hackmd.io/_uploads/SJ8Uv54jh.png) 為什麼是五萬 是因為官方說 5萬到九萬九千九百九是給各公司用的 所以自定義的最好放這區間 ![](https://hackmd.io/_uploads/SJyuic4j3.png) 另外自己常用的最好1~15原因好像是byte 的長度問題 二進位 ## enum ![](https://hackmd.io/_uploads/rkfC6o4in.png) ## grpc vs websocket https://www.infoq.com/articles/websocket-and-http2-coexist/ ## Protocol Buffers & gRPC gRPC 擴充 Protocol Buffers 的語法,因此使用 gRPC 時必須先安裝 Protocol Buffers, 可以先至 protobuf 的 Github 下載 執行檔( e.g. protoc-3.11.3-osx-x86_64.zip ) 進行安裝,安裝方式詳見該檔案夾內的 readme.txt ,在此不多贅述。 記住grpc沒有router 因為她是call自己的function ## protocol buffers ## 工具 vs安裝vscode-proto3 安裝cli 打api的 用BloomRPC(buffers 裡面的posman) 每個欄位都要給123456, 因為她會編譯成二進檔案 所以要唯一 ## 四種方式 ![](https://i.imgur.com/uvXSDmR.png) ## grpc vs api ![](https://i.imgur.com/ovCijbz.png) ## compiler ![](https://i.imgur.com/ejuIOm5.png) 編譯 可看官網 ``` protoc --proto_path=proto --go_out=./pb --go_opt=paths=source_relative \ --go-grpc_out=./pb --go-grpc_opt=paths=source_relative \ proto/*.proto ``` ## 編譯 Protocol Buffer 檔案 `$ protoc *.proto --go_out=plugins=grpc:. --go_opt=paths=source_relative` 在成功編譯好後,應該會看到同樣的資料夾位置出現 *.pb.go 的檔案,這就是編譯好後可以在 Golang 中使用 Protocol Buffer 和 gRPC 的檔案。. ![](https://i.imgur.com/SEwTi16.png) ## protoc flow https://kennychen-blog.herokuapp.com/2022/07/09/Protobuf-%E5%A6%82%E4%BD%95%E9%96%8B%E7%99%BC-codegen-plugin/ ## import 就是import package 但是像是時間 就要 go get github.com/protocolbuffers/protobuf 另外extion 那邊也要加入倒 setting josn那邊 ![](https://i.imgur.com/8Od1M4j.png) 不然他不會知道去哪找 ## gateway ![](https://i.imgur.com/yn9n7Mn.png) 他是算差件 記住他的grpc只能用一元grpc ### 自訂輸出欄位名稱 預設是fullName 改snake的話 ![](https://i.imgur.com/8PlC7Jn.png) ### matedata 獲取matedata get Ip agent之類的 ![](https://i.imgur.com/5EZ1mYk.png) ![](https://i.imgur.com/IbGDSMw.png) 獲取metadata 但是grpc 有些 ex ip 不再metadata裡面 所以要從ctx裡面拉出來 ![](https://i.imgur.com/gegSjKD.png) test的部分 ![](https://i.imgur.com/Q3v9ogX.png) ### swagger ![](https://i.imgur.com/WzmwKai.png) 先搜尋找到這個 然後看關鍵字v2 ... 去搜尋會發現它是一開始安裝的放在bin裡面 可執行黨 所以就help去找他看他能不能匯出一個檔案 會找到 ![](https://i.imgur.com/lQRkibc.png) ![](https://i.imgur.com/SzBeg8a.png) 這兩個 ### 安裝swaager UI 把swagger UI 安裝近來 只要dist資料夾 因為我只要UI部分 init.js 的部分放入對應json 不知道為什麼他不能往上層資料夾找 fileServer用好 ![](https://i.imgur.com/H7pEanJ.png) ## 採坑 go_out= 這最新的會有問題 改用二進制下載就好 import錯誤 https://mileslin.github.io/2020/04/Golang/Import-%E5%85%B6%E4%BB%96-proto/ go_package 是別人導入的位置 所以要加上package name ![](https://i.imgur.com/q7uyTF3.png) ### 安裝步驟 第一安裝 Compile from source 開一個tool資料夾讓他install 第二輸出 ![](https://i.imgur.com/CmEu6Km.png) 一樣指定位置跟source_relation 安裝google.api.http 到import 我使用protoc 所以要把檔案clone下來 ### customer 一些東西 ![](https://i.imgur.com/C45iBCc.png) ### 時間轉換 ![](https://i.imgur.com/U9hugwa.png) new轉換 ## server ![](https://i.imgur.com/rhepuyE.png) server要embed 下面那個struct 這感覺是extend的特別用法 ## validation ![](https://i.imgur.com/tJra8nj.png) ![](https://i.imgur.com/ngdtIQp.png) 先將feild放好 然後建立badrequest 把field放進去 然後建立status 平常也是用這個 接著status放入badrequest ## fieldmask ## 欄位對應 oneof 可以擇一 ![](https://i.imgur.com/2RwYe6g.png) ## stream https://www.cnblogs.com/FireworksEasyCool/p/12693749.html ## health https://www.twle.cn/t/19358 ## grpc-middware https://www.cnblogs.com/FireworksEasyCool/p/12750339.html 看 https://www.cnblogs.com/rickiyang/p/14975552.html ## SSL / TLS https://www.cnblogs.com/rickiyang/p/14981374.html ``` 对于加密传输的部分 gRPC 将它抽出来作为一个组件,可以由用户自由选择。gRPC 内默认提供了两种 内置的认证方式: 基于 CA 证书的 SSL/TLS 认证方式; 基于 Token 的认证方式。 同时也提供了可扩展的用户自定义认证方式。 gRPC 中的连接类型一共有以下 3 种: insecure connection:不使用 TLS 加密; server-side TLS:仅服务端 TLS 加密; mutual TLS:客户端、服务端都使用 TLS 加密 ``` ## convert 時間轉換 ![](https://i.imgur.com/m4Gs7pi.png) ## oneof ![](https://i.imgur.com/xrXArL6.png) 可以讓相似的共用一些東西 例如都是message很多可以共用 ###### tags: `Go`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully