Where to Find Example Code for Using FastProxy: A Complete Repository Guide
FastProxy provides four ready-to-run examples in the examples/ directory—service center, in-proxy, out-proxy, and client—that demonstrate end-to-end encryption, signing, and service routing.
The kingson4wu/fast_proxy repository includes comprehensive example code for using FastProxy in real-world microservice architectures. These runnable demonstrations located in the examples/ folder show how to configure inbound and outbound sidecars, service discovery, and cryptographic request processing without writing boilerplate networking code.
FastProxy Example Components Overview
The repository provides isolated examples for each part of the proxy pipeline. Running them in sequence—center → business service → in-proxy → out-proxy → client—creates a complete end-to-end demonstration of FastProxy’s capabilities.
Service Center (Service Registry)
The service center acts as a minimal registry that stores service names and their network addresses. It enables dynamic service discovery for the proxy layer.
Source: [examples/center/cmd/server.go](https://github.com/kingson4wu/fast_proxy/blob/main/examples/center/cmd/server.go)
func registerHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
name := r.Form.Get("name")
ip := r.Form.Get("ip")
port, _ := strconv.Atoi(r.Form.Get("port"))
register(name, ip, port) // store in local map
fmt.Fprintln(w, "success")
}
Start the registry with go run ./examples/center/cmd/server.go. It listens on port 8080 and maintains an in-memory map of available services.
In-Proxy (Inbound Sidecar)
The in-proxy terminates secure connections, validates request signatures, and decrypts payloads before forwarding to the actual business service. It acts as the entry point for protected microservices.
Source: [examples/inproxy/server.go](https://github.com/kingson4wu/fast_proxy/blob/main/examples/inproxy/server.go)
func main() {
configBytes, _ := ConfigFs.ReadFile("config.yaml")
c := inconfig.LoadYamlConfig(configBytes) // load in-proxy config
sc := center.GetSC(func() string { return c.ServiceRpcHeaderName() })
inproxy.NewServer(c, server.WithServiceCenter(sc)) // start the proxy
}
Run with go run ./examples/inproxy/server.go. The proxy forwards traffic to the downstream service defined in the proxy.forwardAddress field of examples/inproxy/config.yaml.
Out-Proxy (Outbound Sidecar)
The out-proxy applies encryption, HMAC signing, and optional compression before sending traffic to the next hop. It sits between your client and the external network, ensuring all outbound requests meet security policies.
Source: [examples/outproxy/server.go](https://github.com/kingson4wu/fast_proxy/blob/main/examples/outproxy/server.go)
func main() {
configBytes, _ := ConfigFs.ReadFile("config.yaml")
c := outconfig.LoadYamlConfig(configBytes) // load out-proxy config
sc := center.GetSC(func() string { return outconfig.Get().ServiceRpcHeaderName() })
outproxy.NewServer(c, server.WithServiceCenter(sc)) // start the proxy
}
Execute with go run ./examples/outproxy/server.go. The out-proxy encrypts requests according to the serviceConfig section in examples/outproxy/config.yaml.
HTTP Client
The client example demonstrates how to set required routing headers and call the proxy pipeline. It routes through the out-proxy when proxyEnable is configured as true.
Source: [examples/client/client.go](https://github.com/kingson4wu/fast_proxy/blob/main/examples/client/client.go)
func send(clientName, destServiceName string) {
req, _ := http.NewRequest("POST",
fmt.Sprintf("http://%s/%s/api/service", center.GetAddress("out_proxy"), destServiceName),
strings.NewReader("param=hello"))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("C_ServiceName", clientName) // required header for routing
resp, _ := http.DefaultClient.Do(req)
// handle response …
}
Run the client with go run ./examples/client/client.go. The required header C_ServiceName tells the out-proxy which destination service should receive the request.
Configuration Files and Core Implementation
Each example embeds a YAML configuration file that defines routing rules, cryptographic keys, and FastHTTP settings.
- Out-proxy configuration: [
examples/outproxy/config.yaml](https://github.com/kingson4wu/fast_proxy/blob/main/examples/outproxy/config.yaml) shows encryption, signing, and compression settings. - In-proxy configuration:
examples/inproxy/config.yamldefines theproxy.forwardAddressand decryption parameters.
Key implementation files referenced by the examples include:
- Core engines:
outproxy/outproxy.goandinproxy/inproxy.gocontainoutproxy.NewServerandinproxy.NewServer, the primary entry points that wire configuration and the HTTP handler stack. - Reverse proxy logic:
outproxy/internal/proxy/reverseProxy.gohandles request forwarding, encryption/decryption, and signature verification. - Cryptography:
common/sign/sign.goandoutproxy/internal/encrypt/encrypt.goprovide symmetric encryption and HMAC signing utilities. - Configuration parsing:
outproxy/outconfig/config.goandinproxy/inconfig/config.goparse YAML and support Apollo remote configuration. - Service-center integration:
common/server/server.goprovides theWithServiceCenteroption used in both proxy examples.
Summary
- Four main examples are located in
examples/center,examples/inproxy,examples/outproxy, andexamples/client, each demonstrating a specific layer of the proxy architecture. - Configuration is YAML-based via
config.yamlfiles that control encryption, signing, compression, and routing. - Key bootstrap functions include
inproxy.NewServer,outproxy.NewServer, andcenter.GetSCfor service discovery. - Execution order for a full demonstration: start the service center, business service, in-proxy, out-proxy, and finally the client to observe the complete encrypted flow.
Frequently Asked Questions
Where is the FastProxy example code located?
All example code resides in the examples/ directory at the root of the kingson4wu/fast_proxy repository. You will find subdirectories for center, inproxy, outproxy, and client, each containing runnable Go files and accompanying YAML configurations.
How do I run the FastProxy examples locally?
Execute the examples in this order: first go run ./examples/center/cmd/server.go, then start your business service, followed by go run ./examples/inproxy/server.go, go run ./examples/outproxy/server.go, and finally go run ./examples/client/client.go. This sequence establishes the service registry, proxy layers, and client necessary for end-to-end testing.
What configuration files are required for the examples?
Each proxy component requires a config.yaml file located in its respective examples/ subdirectory. The out-proxy uses examples/outproxy/config.yaml to define encryption keys and signing algorithms, while the in-proxy uses examples/inproxy/config.yaml to set the proxy.forwardAddress and validation parameters.
Which functions initialize the proxy servers in the examples?
The examples use inproxy.NewServer(c, server.WithServiceCenter(sc)) for the inbound sidecar and outproxy.NewServer(c, server.WithServiceCenter(sc)) for the outbound sidecar. These functions, implemented in inproxy/inproxy.go and outproxy/outproxy.go, accept a configuration object and a service-center option to bootstrap the HTTP handlers.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →