How to Integrate FastProxy into Your Existing Infrastructure: 3 Deployment Patterns

You can integrate FastProxy into existing infrastructure by embedding it as a Go SDK, deploying it as a sidecar container, or running it as a central gateway, depending on whether you need minimal footprint, per-service isolation, or unified traffic management.

FastProxy is a production‑grade, Go‑native service proxy from the kingson4wu/fast_proxy repository. Its modular architecture separates ingress handling (InProxy), egress handling (OutProxy), and service discovery (Center), allowing you to adopt only the components you need without rewriting existing services.

Core Architectural Components

Before integrating, understand the three primary building blocks defined in the source tree:

Component Role Key Source File
Center Orchestrates service metadata and dynamic rule sets; provides address resolution for proxies. center/center.go
InProxy Terminates inbound secure channels, validates signatures, applies throttling, and forwards to target services. inproxy/inproxy.go
OutProxy Handles outbound traffic, performs forward‑address routing, and optionally encrypts payloads. outproxy/outproxy.go

Both proxy types rely on the shared common/server/server.go wrapper for graceful shutdown and structured logging via common/logger/zap/zap.go. Service discovery abstracts are located in common/servicediscovery/servicediscovery.go.

Three Strategies to Integrate FastProxy

Embedded SDK (Go Library)

Import FastProxy directly into your existing Go service to eliminate network hops. This approach minimizes latency and operational complexity by running the proxy logic in the same process as your business code.

Key files to reference:

Sidecar Deployment

Build the standalone binaries using the provided Makefile and run them as separate containers or processes alongside your service. This pattern keeps the proxy lifecycle independent of your application, enabling independent scaling and rolling updates.

Build command:

make  # produces ./in-proxy and ./out-proxy

Configuration is loaded via YAML files (e.g., examples/inproxy/config.yaml and examples/outproxy/config.yaml), where proxy.forwardAddress specifies the upstream destination.

Central Gateway

Deploy a single Center instance (default port 8080) and shared InProxy/OutProxy pairs to front an entire microservice mesh. Existing services register themselves with the Center, and the proxies handle all encryption, traffic shaping, and observability centrally.

Registration helper: examples/center/center.go provides RegisterAsync() for dynamic service enrollment.

Configuration and Service Discovery

FastProxy uses Viper for configuration management. The forward address for outbound traffic is read via viper.GetString("proxy.forwardAddress") as seen in outproxy/outconfig/yaml_config.go.

Service discovery relies on the ServiceCenter abstraction. Proxies fetch addresses through the GetSC helper, which queries the Center’s HTTP API at runtime:

sc := servicediscovery.Create().
    AddressFunc(func(serviceName string) *servicediscovery.Address {
        addr := center.GetAddress(serviceName) // Center lookup
        return &servicediscovery.Address{Host: addr.Host, Port: addr.Port}
    })

Code Examples

Embedded Library Integration

Run InProxy and OutProxy within your existing Go process:

package main

import (
    "github.com/Kingson4Wu/fast_proxy/inproxy"
    "github.com/Kingson4Wu/fast_proxy/outproxy"
    "github.com/Kingson4Wu/fast_proxy/inproxy/inconfig"
    "github.com/Kingson4Wu/fast_proxy/outproxy/outconfig"
)

func main() {
    // Configure inbound proxy
    inCfg := inconfig.LoadYamlConfig([]byte(`
proxy:
  listenPort: 8081
`))
    go inproxy.NewServer(inCfg)

    // Configure outbound proxy
    outCfg := outconfig.LoadYamlConfig([]byte(`
proxy:
  forwardAddress: "127.0.0.1:9090"
`))
    outproxy.NewServer(outCfg)

    select {} // Block forever
}

Sidecar Binary Deployment

Build and launch the proxies as standalone processes:


# Build binaries

make

# Start Center (service discovery)

./center &

# Start sidecars with configuration

./in-proxy -c ./examples/inproxy/config.yaml &
./out-proxy -c ./examples/outproxy/config.yaml &

Service Registration with Center

Register a custom service dynamically:

package main

import (
    "log"
    "net/http"
    "github.com/Kingson4Wu/fast_proxy/common/network"
    "github.com/Kingson4Wu/fast_proxy/examples/center"
)

func main() {
    srv := &http.Server{
        Addr: ":9000",
        Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            w.Write([]byte(`{"msg":"hello from my-service"}`))
        }),
    }

    // Register with Center
    ip := network.GetIntranetIp()
    stop := center.RegisterAsync("my-service", ip, 9000)

    if err := srv.ListenAndServe(); err != nil {
        close(stop)
        log.Fatal(err)
    }
}

Summary

  • FastProxy provides three integration paths: embedded SDK for minimal latency, sidecar deployment for operational isolation, and central gateway for unified mesh management.
  • The Center component (center/center.go) acts as the control plane, while InProxy and OutProxy handle ingress and egress traffic respectively.
  • Configuration uses YAML files parsed via Viper, with critical parameters like proxy.forwardAddress defined in outproxy/outconfig/yaml_config.go.
  • Service discovery relies on the ServiceCenter abstraction in common/servicediscovery/servicediscovery.go, which queries the Center’s HTTP API at runtime.

Frequently Asked Questions

How do I configure the forward address for outbound traffic?

Set the proxy.forwardAddress key in your YAML configuration file. The outproxy/outconfig/yaml_config.go file uses Viper to read this value via viper.GetString("proxy.forwardAddress"), directing all outbound requests to the specified upstream endpoint.

Can I run FastProxy without the Center component?

Yes, but you lose dynamic service discovery. If you omit the Center, you must statically configure the forwardAddress in OutProxy and the target endpoints in InProxy. The Center (center/center.go) is only required for runtime address resolution and service registration.

What is the difference between InProxy and OutProxy?

InProxy (inproxy/inproxy.go) terminates inbound connections, validates request signatures, applies rate limiting, and forwards to your service. OutProxy (outproxy/outproxy.go) intercepts outbound calls from your service, resolves target addresses via the Center, and optionally encrypts payloads before transmission.

How do I enable graceful shutdown for the proxy servers?

Both proxies use the shared common/server/server.go wrapper. When starting the server, pass server.WithShutdownTimeout(5*time.Second) to the Start() method. This ensures the HTTP server drains active connections before exiting when it receives a termination signal.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →