mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02:00
go-proxy ls-route now query api server first, then fallback to read from config file
This commit is contained in:
6
.github/workflows/docker-image.yml
vendored
6
.github/workflows/docker-image.yml
vendored
@@ -124,9 +124,3 @@ jobs:
|
|||||||
- name: Inspect image
|
- name: Inspect image
|
||||||
run: |
|
run: |
|
||||||
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
|
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
|
||||||
|
|
||||||
- name: Tag as latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref_name, '-')
|
|
||||||
run: |
|
|
||||||
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ RUN apk add --no-cache tzdata
|
|||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# Only copy go.mod and go.sum initially for better caching
|
# Only copy go.mod and go.sum initially for better caching
|
||||||
COPY go.mod go.sum /src
|
COPY go.mod go.sum /src/
|
||||||
|
|
||||||
# Utilize build cache
|
# Utilize build cache
|
||||||
RUN --mount=type=cache,target="/go/pkg/mod" \
|
RUN --mount=type=cache,target="/go/pkg/mod" \
|
||||||
go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
|
go mod download -x
|
||||||
|
|
||||||
ENV GOCACHE=/root/.cache/go-build
|
ENV GOCACHE=/root/.cache/go-build
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,14 @@ func main() {
|
|||||||
printJSON(cfg.Value())
|
printJSON(cfg.Value())
|
||||||
return
|
return
|
||||||
case common.CommandListRoutes:
|
case common.CommandListRoutes:
|
||||||
printJSON(cfg.RoutesByAlias())
|
routes, err := apiUtils.ListRoutes()
|
||||||
|
if err.HasError() {
|
||||||
|
log.Printf("failed to connect to api server: %s", err)
|
||||||
|
log.Printf("falling back to config file")
|
||||||
|
printJSON(cfg.RoutesByAlias())
|
||||||
|
} else {
|
||||||
|
printJSON(routes)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
case common.CommandDebugListEntries:
|
case common.CommandDebugListEntries:
|
||||||
printJSON(cfg.DumpEntries())
|
printJSON(cfg.DumpEntries())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -29,3 +30,20 @@ func ReloadServer() E.NestedError {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ListRoutes() (map[string]map[string]any, E.NestedError) {
|
||||||
|
resp, err := httpClient.Get(fmt.Sprintf("%s/v1/list/routes", common.APIHTTPURL))
|
||||||
|
if err != nil {
|
||||||
|
return nil, E.From(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, E.Failure("list routes").Extraf("status code: %v", resp.StatusCode)
|
||||||
|
}
|
||||||
|
var routes map[string]map[string]any
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&routes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, E.From(err)
|
||||||
|
}
|
||||||
|
return routes, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user