惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
C
Cisco Blogs
The Hacker News
The Hacker News
T
Threatpost
S
Schneier on Security
K
Kaspersky official blog
Spread Privacy
Spread Privacy
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
NISL@THU
NISL@THU
量子位
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
V
V2EX
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
L
LangChain Blog
W
WeLiveSecurity
Cloudbric
Cloudbric

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Generating and publishing Go gRPC stubs as separate modules via GitLab CI/CD
m1s1ma · 2026-06-26 · via DEV Community

Setting up gRPC stub generation for Go and connecting them as a module

Keeping proto contracts in a single repository is convenient, but pulling the entire thing into every service is not. Let's walk through how to automatically generate Go stubs from proto files, version them as standalone Go modules, and publish them via GitLab CI/CD. Bonus: Swagger documentation and GitLab Pages.

Everything described here targets private free-tier GitLab. For self-hosted, paid plans, or public repositories the setup is considerably simpler — a number of the limitations simply don't apply.


Notes before you start

The approach requires some dev environment setup: standard SSH access to the repository and a few environment variables on each developer's machine:

GOPRIVATE=gitlab.com/your-group
GOPROXY=direct
GONOSUMDB=gitlab.com/your-group

Services that consume the stubs will need a vendor directory — both for local runs and in pipelines during linting, testing, and builds. This is because Go can't download private modules from GitLab without additional auth configuration bypassing the proxy.

In CI environments, access is handled via CI_JOB_TOKEN. A typical before_script for services consuming the stubs looks like this:

default:
  image: golang:${GO_VERSION}
  cache:
    key: go-mod
    paths:
      - go/pkg/mod
      - .cache/go-build
  before_script:
    - go version
    - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf "https://gitlab.com/"
    - go env -w GOPRIVATE=gitlab.com/chichilaki
    - go env -w GONOSUMDB=gitlab.com/chichilaki
    - go mod vendor


Repository structure

Create the following groups and repositories:

  • group/proto — proto contracts; the only repository you'll edit by hand.
  • group/proto-stubs — a group for generated stubs; create the repositories inside it ahead of time, empty.
  • group/proto-stubs/common, group/proto-stubs/user, group/proto-stubs/admin, etc. — one repository per module.
  • group/service — any service that consumes the stubs.

Stub repositories

Each stub gets its own Go module repository. In my case there's a contract for shared entities (common) and contracts for services: user, admin, runner.

Configuring access for CI_JOB_TOKEN

Since every service uses CI_JOB_TOKEN in its pipeline to access stub repositories, you need to explicitly allow that access.

For each stub repository, go to Settings -> CI/CD -> Job token permissions and add the proto contracts repository and the group containing services that consume the stubs.

One important nuance: if some stubs depend on others — for example, admin imports common — you also need to add the stub repositories group to the access settings of admin.git. Otherwise go get in CI will fail with an authentication error, and the reason won't be obvious at all.

Paid and self-hosted GitLab lets you grant access at the group level — everything is configured in one place.

Why .git in the module name

The module name includes a .git suffix:

gitlab.com/chichilaki/mgs/proto-go-stubs/common.git

This is intentional. When resolving a module path from GitLab, Go can't figure out on its own where the repository path ends and the in-repo package path begins. The .git suffix gives it an explicit hint. Without it, go get will try to fetch module metadata from the wrong path and fail.


Proto contracts repository

This is the repository that triggers the stub generation and publishing pipeline.

Versioning

The publish job runs only for branches named vX.X.X. On publish, a matching tag is created in the stub repository. This means the branch name in the proto repo directly becomes the Go module version. Want to release v1.2.3 — create a branch called v1.2.3 and run the pipeline.

Setting up a Personal Access Token

Note: GitLab Next recently added the ability to configure CI_JOB_TOKEN access for pushing to repositories — worth checking, this step may soon become unnecessary.

In the free tier of GitLab you can't issue an access token scoped to a group of repositories, so we use a Personal Access Token instead.

Go to Profile Settings -> Access Tokens and create a token with the following permissions: api, read_api, read_repository, write_repository. The token is shown only once — save it immediately.

Then in the proto contracts repository: Settings -> CI/CD -> Variables. Create a variable with:

  • type: Variable
  • visibility: Masked and hidden
  • flag: Protected

If there are multiple developers on the team — each person creates their own token and their own variable, e.g. CI_PUSH_TOKEN_USERNAME. In the pipeline, the right token is selected via rules with a condition on GITLAB_USER_LOGIN — more on that below.

Setting up Branch Rules

To make protected variables available outside the main branch: Settings -> Repository -> Branch Rules -> Add rule. The mask v* gives any branch starting with v access to protected variables and tokens. Without this step, the pipeline on branch v1.0.0 simply won't see the token.


buf configuration

buf.yaml describes dependencies and linting rules; buf.gen.yaml covers the generation plugins.

In buf.gen.yaml we use local with go run instead of a globally installed protoc and plugins — Go will download the required versions on first run. This eliminates version mismatch issues between developer machines and CI.

Both files are included in full in the appendix.

Proto file examples

The go_package option must include the .git suffix — that's how Go will resolve the module import:

// common.proto
syntax = "proto3";
package common.v1;
option go_package = "gitlab.com/chichilaki/mgs/proto-go-stubs/common.git/v1";

For service contracts with grpc-gateway HTTP annotations and Swagger options, the structure looks like this:

// admin.proto
syntax = "proto3";
package admin.v1;
option go_package = "gitlab.com/chichilaki/mgs/proto-go-stubs/admin.git/v1";

import "common/v1/common.proto";
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  info: { title: "Control Plane ADMIN API"; version: "1.0"; };
  security_definitions: {
    security: {
      key: "Bearer";
      value: {
        type: TYPE_API_KEY;
        in: IN_HEADER;
        name: "Authorization";
        description: "Admin Bearer token";
      };
    };
  };
  security: { security_requirement: { key: "Bearer"; } };
};

service AdminService {
  rpc ListRunners(ListRunnersRequest) returns (ListRunnersResponse) {
    option (google.api.http) = { get: "/v1/runners" };
  }
  rpc GetRunnerStatus(GetRunnerStatusRequest) returns (GetRunnerStatusResponse) {
    option (google.api.http) = { get: "/v1/runners/{runner_id.runner_id}/status" };
  }
  // ...
}


CI/CD pipeline

The proto repository pipeline has three stages: lint, generate, commit. The full version is in the appendix.

The generate job

Runs buf generate, then creates a go.mod with the correct module name (including .git) for each module. Artifacts are passed to the next job via artifacts.paths.

Key detail: go mod init is only called if go.mod doesn't already exist, to avoid overwriting the file on re-runs. Otherwise the module would be re-initialized on every run and lose its dependencies.

The commit-generated job

Clones each target repository, replaces its contents with the generated files, copies swagger.json, updates dependencies via go mod tidy, commits, and creates a version tag.

Token selection per user is handled via rules with a condition on GITLAB_USER_LOGIN — this lets each developer use their own Personal Access Token without sharing it with teammates:

rules:
  - if: $CI_COMMIT_BRANCH =~ /^v\d+\.\d+\.\d+$/
    variables:
      PROTO_VERSION: $CI_COMMIT_BRANCH
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    when: never
  - if: $GITLAB_USER_LOGIN == "End1essRage"
    variables:
      PUSH_TOKEN: $CI_PUSH_TOKEN
  - if: $GITLAB_USER_LOGIN == "stivvhuys"
    variables:
      PUSH_TOKEN: $CI_PUSH_TOKEN_GENGAVSOV
  - when: never

If PUSH_TOKEN ends up empty — the job fails in before_script with an explicit error rather than a cryptic 403 somewhere mid-script. This is an intentional check.

For modules that depend on common, the script explicitly adds a require with the correct version:

if [ "$module" != "common" ]; then
  go get gitlab.com/chichilaki/mgs/proto-go-stubs/common.git@$PROTO_VERSION
fi

This matters: without an explicit go get with the tag, go mod tidy will pull in latest instead of the version we just published.


The service consuming stubs

Let's look at the consumer side — a service that wants to host its own Swagger documentation, serve it over HTTP, and interact with the API through Swagger UI.

Embedding swagger.json via go:embed

A docs package is created at the project root:

package docs

import _ "embed"

//go:embed control-plane-admin.swagger.json
var AdminSwaggerJSON []byte

//go:embed control-plane-user.swagger.json
var UserSwaggerJSON []byte

Imported in main.go as a side-effect:

import _ "gitlab.com/chichilaki/mgs/control-plane/docs"

mux.HandleFunc("/swagger/admin/doc.json", func(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    _, _ = w.Write(docs.AdminSwaggerJSON)
})

mux.HandleFunc("/swagger/user/doc.json", func(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    _, _ = w.Write(docs.UserSwaggerJSON)
})

go:embed compiles the files directly into the binary — no separate static file serving needed, and no risk of the documentation going out of sync with the code.

Syncing swagger.json

Documentation is synced in three places: a pre-commit hook, a Taskfile, and the service CI pipeline. The logic is the same in all three: clone the stub repository into a temp directory, grab v1/<service>.swagger.json, and put it in docs/.

Locally we use SSH; in CI — CI_JOB_TOKEN. The corresponding Taskfile and CI configs are in the appendix.

Local stack: Traefik + Swagger UI

Brought up via Compose. Note: the BASE_URL in the Swagger UI config and the PathPrefix in the Traefik rule must match — otherwise the UI will load but won't be able to resolve its own assets.

swagger-ui:
  image: swaggerapi/swagger-ui:v5.9.0
  environment:
    BASE_URL: /swagger
    URLS: >
      [
        { "url": "/cp-swagger/swagger/admin/doc.json", "name": "ADMIN control-plane" },
        { "url": "/cp-swagger/swagger/user/doc.json", "name": "USER control-plane" }
      ]
  labels:
    - "traefik.http.routers.swagger.rule=Host(`localhost`) && PathPrefix(`/swagger`)"
    - "traefik.http.routers.swagger.entrypoints=web"
    - "traefik.http.services.swagger.loadbalancer.server.port=8080"

Service route with /cp prefix stripping:

control-plane:
  labels:
        # ===== API =====
      - "traefik.http.routers.cp-api.rule=Host(`localhost`) && PathPrefix(`/cp`)"
      - "traefik.http.routers.cp-api.entrypoints=web"
      - "traefik.http.routers.cp-api.service=cp"

      - "traefik.http.middlewares.cp-strip.stripprefix.prefixes=/cp"
      - "traefik.http.routers.cp-api.middlewares=cp-strip"

      - "traefik.http.services.cp.loadbalancer.server.port=9100"
      # Enable health check for the load balancer
      - "traefik.http.services.cp.loadbalancer.healthcheck.path=/health"
      - "traefik.http.services.cp.loadbalancer.healthcheck.interval=10s"
      - "traefik.http.services.cp.loadbalancer.healthcheck.timeout=3s"
      - "traefik.http.services.cp.loadbalancer.healthcheck.scheme=http"
      # Swagger proxy via Traefik
      # ===== SWAGGER =====
      - "traefik.http.routers.cp-swagger.rule=Host(`localhost`) && PathPrefix(`/cp-swagger`)"
      - "traefik.http.routers.cp-swagger.entrypoints=web"
      - "traefik.http.routers.cp-swagger.service=cp-swagger"

      - "traefik.http.middlewares.cp-swagger-strip.stripprefix.prefixes=/cp-swagger"
      - "traefik.http.routers.cp-swagger.middlewares=cp-swagger-strip"

      - "traefik.http.services.cp-swagger.loadbalancer.server.port=9100"


Bonus: GitLab Pages with Swagger UI

It's handy to have documentation available not just locally but at a permanent URL. GitLab Pages solves this without any separate hosting — just put the artifacts in a public folder.

The pages job creates the public folder, places the swagger files there, and generates an index.html with a CDN-hosted Swagger UI. It runs on master and dev branches. The full job is in the appendix.

CI: fetch-swagger + pages

fetch-swagger:
  stage: prepare
  image: alpine:latest
  before_script:
    - apk add --no-cache git
  script:
    - mkdir -p docs
    - |
      for REPO in admin user; do
        git clone --depth 1 \
          "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/chichilaki/mgs/proto-go-stubs/${REPO}.git" \
          "/tmp/${REPO}"
        cp "/tmp/${REPO}/v1/${REPO}.swagger.json" "docs/control-plane-${REPO}.swagger.json"
        rm -rf "/tmp/${REPO}"
      done
  artifacts:
    paths:
      - docs/*.swagger.json

pages:
  stage: pages
  image: alpine:latest
  script:
    - mkdir -p public/docs
    - cp docs/*.swagger.json public/docs/ || echo "No swagger files"
    - |
      cat > public/index.html << 'EOF'
      <!DOCTYPE html>
      <html>
      <head>
        <title>API Documentation</title>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css">
      </head>
      <body>
        <div id="swagger-ui"></div>
        <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-standalone-preset.js"></script>
        <script>
          window.onload = function() {
            window.ui = SwaggerUIBundle({
              urls: [
                { url: "./docs/control-plane-admin.swagger.json", name: "Admin API" },
                { url: "./docs/control-plane-user.swagger.json", name: "User API" }
              ],
              dom_id: '#swagger-ui',
              deepLinking: true,
              presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
              layout: "StandaloneLayout"
            });
          }
        </script>
      </body>
      </html>
      EOF
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
    - if: $CI_COMMIT_BRANCH == "dev"


Conclusion

Here's what we end up with: proto contracts in a single repository, automatic stub generation and publishing triggered by creating a branch like v1.0.0, separate Go modules per service, Swagger documentation as part of the same pipeline, and Pages with a UI for browsing it.

The main challenge with free-tier GitLab is token management. On a paid plan or self-hosted, most of that overhead disappears: you can grant access at the group level and use a single token. But even as described, everything works reliably.