mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
use the new protobuf package and other minor stuff
Former-commit-id: 29bf71e8a73d34b27c6f5fe3f12c4ea1cc2b84b2
This commit is contained in:
parent
d55bb34766
commit
29d98ac281
33
.github/workflows/go.yml
vendored
33
.github/workflows/go.yml
vendored
|
@ -1,33 +0,0 @@
|
|||
name: Go
|
||||
on: [push]
|
||||
env:
|
||||
GOPROXY: "https://goproxy.io"
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- uses: actions/cache@v1
|
||||
id: cache
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Set up Go 1.14
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.14
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@master
|
||||
|
||||
# - name: Get dependencies
|
||||
# run: |
|
||||
# go get -v -t -d ./...
|
||||
- name: Build
|
||||
run: go build -v .
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
# Iris Web Framework <a href="README_GR.md"><img width="20px" src="https://iris-go.com/images/flag-greece.svg" /></a> <a href="README_FR.md"><img width="20px" src="https://iris-go.com/images/flag-france.svg" /></a> <a href="README_ZH.md"><img width="20px" src="https://iris-go.com/images/flag-china.svg" /></a> <a href="README_ES.md"><img width="20px" src="https://iris-go.com/images/flag-spain.png" /></a> <a href="README_FA.md"><img width="20px" src="https://iris-go.com/images/flag-iran.svg" /></a> <a href="README_RU.md"><img width="20px" src="https://iris-go.com/images/flag-russia.svg" /></a> <a href="README_KO.md"><img width="20px" src="https://iris-go.com/images/flag-south-korea.svg?v=12" /></a>
|
||||
|
||||
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/kataras/iris) [![FOSSA Status](https://img.shields.io/badge/LICENSE%20SCAN-PASSING❤️-CD2956?style=for-the-badge&logo=fossa)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkataras%2Firis?ref=badge_shield)<!--[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/iris)--><!--[![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/iris/v12@v12.2.0)--> [![view examples](https://img.shields.io/badge/learn%20by-examples-0C8EC5.svg?style=for-the-badge&logo=go)](https://github.com/kataras/iris/tree/master/_examples) [![chat](https://img.shields.io/gitter/room/iris_go/community.svg?color=7E18DD&logo=gitter&style=for-the-badge)](https://gitter.im/iris_go/community)<!--[![donate on PayPal](https://img.shields.io/badge/support-PayPal-blue.svg?style=for-the-badge)](https://www.paypal.me/kataras)--><!-- [![release](https://img.shields.io/badge/release%20-v12.0-0077b3.svg?style=for-the-badge)](https://github.com/kataras/iris/releases) -->
|
||||
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/kataras/iris) [![view examples](https://img.shields.io/badge/examples%20-173-a83adf.svg?style=for-the-badge&logo=go)](https://github.com/kataras/iris/tree/master/_examples) [![chat](https://img.shields.io/gitter/room/iris_go/community.svg?color=cc2b5e&logo=gitter&style=for-the-badge)](https://gitter.im/iris_go/community) <!--[![FOSSA Status](https://img.shields.io/badge/LICENSE%20SCAN-PASSING❤️-CD2956?style=for-the-badge&logo=fossa)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkataras%2Firis?ref=badge_shield)--> [![donate](https://img.shields.io/badge/support-Iris-blue.svg?style=for-the-badge&logo=paypal)](https://www.paypal.me/kataras) <!--[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/iris)--><!--[![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/iris/v12@v12.2.0)--> <!--[![donate on PayPal](https://img.shields.io/badge/support-PayPal-blue.svg?style=for-the-badge)](https://www.paypal.me/kataras)--><!-- [![release](https://img.shields.io/badge/release%20-v12.0-0077b3.svg?style=for-the-badge)](https://github.com/kataras/iris/releases) -->
|
||||
|
||||
<a href="https://iris-go.com"> <img align="right" src="https://iris-go.com/images/logo-w169.png"></a>
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ package helloworld
|
|||
|
||||
import (
|
||||
context "context"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
@ -39,10 +38,6 @@ const (
|
|||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
// The request message containing the user's name.
|
||||
type HelloRequest struct {
|
||||
state protoimpl.MessageState
|
||||
|
|
3
cache/client/client.go
vendored
3
cache/client/client.go
vendored
|
@ -153,10 +153,11 @@ func (h *ClientHandler) ServeHTTP(ctx context.Context) {
|
|||
return
|
||||
}
|
||||
// go Client.Do(request)
|
||||
_, err = Client.Do(request)
|
||||
resp, err := Client.Do(request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
resp.Body.Close()
|
||||
} else {
|
||||
// get the status code , content type and the write the response body
|
||||
ctx.ContentType(response.Header.Get(cfg.ContentTypeHeader))
|
||||
|
|
|
@ -530,7 +530,7 @@ func WithSitemap(startURL string) Configurator {
|
|||
|
||||
handler := func(ctx Context) {
|
||||
ctx.ContentType(context.ContentXMLHeaderValue)
|
||||
ctx.Write(contentCopy)
|
||||
ctx.Write(contentCopy) // nolint:errcheck
|
||||
}
|
||||
if app.builded {
|
||||
routes := app.CreateRoutes([]string{MethodGet, MethodHead, MethodOptions}, s.Path, handler)
|
||||
|
@ -625,7 +625,8 @@ func (tc *TunnelingConfiguration) isEnabled() bool {
|
|||
}
|
||||
|
||||
func (tc *TunnelingConfiguration) isNgrokRunning() bool {
|
||||
_, err := http.Get(tc.WebInterface)
|
||||
resp, err := http.Get(tc.WebInterface)
|
||||
resp.Body.Close()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
|
@ -723,6 +724,7 @@ func (tc TunnelingConfiguration) stopTunnel(t Tunnel) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != StatusNoContent {
|
||||
return fmt.Errorf("stop return an unexpected status code: %d", resp.StatusCode)
|
||||
|
@ -904,7 +906,7 @@ type Configuration struct {
|
|||
DisableBodyConsumptionOnUnmarshal bool `json:"disableBodyConsumptionOnUnmarshal,omitempty" yaml:"DisableBodyConsumptionOnUnmarshal" toml:"DisableBodyConsumptionOnUnmarshal"`
|
||||
// FireEmptyFormError returns if set to tue true then the `context.ReadBody/ReadForm`
|
||||
// will return an `iris.ErrEmptyForm` on empty request form data.
|
||||
FireEmptyFormError bool `json:"fireEmptyFormError,omitempty" yaml:"FireEmptyFormError" yaml:"FireEmptyFormError"`
|
||||
FireEmptyFormError bool `json:"fireEmptyFormError,omitempty" yaml:"FireEmptyFormError" toml:"FireEmptyFormError"`
|
||||
|
||||
// TimeFormat time format for any kind of datetime parsing
|
||||
// Defaults to "Mon, 02 Jan 2006 15:04:05 GMT".
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
|
||||
"github.com/Shopify/goreferrer"
|
||||
"github.com/fatih/structs"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/iris-contrib/blackfriday"
|
||||
"github.com/iris-contrib/schema"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
@ -39,6 +38,7 @@ import (
|
|||
"github.com/vmihailenco/msgpack/v5"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
"golang.org/x/time/rate"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
@ -1879,8 +1879,6 @@ func (ctx *context) FullRequestURI() string {
|
|||
return ctx.AbsoluteURI(ctx.Path())
|
||||
}
|
||||
|
||||
const xForwardedForHeaderKey = "X-Forwarded-For"
|
||||
|
||||
// RemoteAddr tries to parse and return the real client's request IP.
|
||||
//
|
||||
// Based on allowed headers names that can be modified from Configuration.RemoteAddrHeaders.
|
||||
|
@ -2396,14 +2394,12 @@ func (ctx *context) URLParamBool(name string) (bool, error) {
|
|||
// URLParams returns a map of GET query parameters separated by comma if more than one
|
||||
// it returns an empty map if nothing found.
|
||||
func (ctx *context) URLParams() map[string]string {
|
||||
values := map[string]string{}
|
||||
|
||||
q := ctx.request.URL.Query()
|
||||
if q != nil {
|
||||
values := make(map[string]string, len(q))
|
||||
|
||||
for k, v := range q {
|
||||
values[k] = strings.Join(v, ",")
|
||||
}
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
@ -4815,7 +4811,7 @@ func (rs *rateReadSeeker) Read(buf []byte) (int, error) {
|
|||
if n <= 0 {
|
||||
return n, err
|
||||
}
|
||||
rs.limiter.WaitN(rs.ctx, n)
|
||||
err = rs.limiter.WaitN(rs.ctx, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,12 @@ func (w *ResponseRecorder) Clone() ResponseWriter {
|
|||
wc.headers = w.headers
|
||||
wc.chunks = w.chunks[0:]
|
||||
if resW, ok := w.ResponseWriter.(*responseWriter); ok {
|
||||
wc.ResponseWriter = &(*resW) // clone it
|
||||
wc.ResponseWriter = &responseWriter{
|
||||
ResponseWriter: resW.ResponseWriter,
|
||||
statusCode: resW.statusCode,
|
||||
written: resW.written,
|
||||
beforeFlush: resW.beforeFlush,
|
||||
} // clone it
|
||||
} else { // else just copy, may pointer, developer can change its behavior
|
||||
wc.ResponseWriter = w.ResponseWriter
|
||||
}
|
||||
|
|
|
@ -42,10 +42,11 @@ func TestFromStdWithNext(t *testing.T) {
|
|||
basicauth := "secret"
|
||||
passed := "ok"
|
||||
|
||||
type contextKey string
|
||||
stdWNext := func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
if username, password, ok := r.BasicAuth(); ok &&
|
||||
username == basicauth && password == basicauth {
|
||||
ctx := stdContext.WithValue(r.Context(), "key", "ok")
|
||||
ctx := stdContext.WithValue(r.Context(), contextKey("key"), "ok")
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
return
|
||||
}
|
||||
|
@ -54,7 +55,7 @@ func TestFromStdWithNext(t *testing.T) {
|
|||
|
||||
h := handlerconv.FromStdWithNext(stdWNext)
|
||||
next := func(ctx context.Context) {
|
||||
ctx.WriteString(ctx.Request().Context().Value("key").(string))
|
||||
ctx.WriteString(ctx.Request().Context().Value(contextKey("key")).(string))
|
||||
}
|
||||
|
||||
app := iris.New()
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestProxy(t *testing.T) {
|
|||
t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err)
|
||||
}
|
||||
// main server
|
||||
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutStartupLog)
|
||||
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutStartupLog) // nolint:errcheck
|
||||
|
||||
e := httptest.NewInsecure(t, httptest.URL("http://"+listener.Addr().String()))
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
|
||||
|
|
|
@ -395,7 +395,7 @@ func (su *Supervisor) runTLS(getCertificate func(*tls.ClientHelloInfo) (*tls.Cer
|
|||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
||||
// tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, G402: TLS Bad Cipher Suite
|
||||
0xC028, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
|
||||
},
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
|
|||
// before sort.
|
||||
for _, r := range registeredRoutes {
|
||||
if r.topLink != nil {
|
||||
bindMultiParamTypesHandler(r.topLink, r)
|
||||
bindMultiParamTypesHandler(r)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
|
|||
return errgroup.Check(rp)
|
||||
}
|
||||
|
||||
func bindMultiParamTypesHandler(top *Route, r *Route) {
|
||||
func bindMultiParamTypesHandler(r *Route) {
|
||||
r.BuildHandlers()
|
||||
|
||||
// println("here for top: " + top.Name + " and current route: " + r.Name)
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestOnAnyErrorCode(t *testing.T) {
|
|||
func checkAndClearBuf(t *testing.T, buff *bytes.Buffer, expected string) {
|
||||
t.Helper()
|
||||
|
||||
if got, expected := buff.String(), expected; got != expected {
|
||||
if got := buff.String(); got != expected {
|
||||
t.Fatalf("expected middleware to run before the error handler, expected: '%s' but got: '%s'", expected, got)
|
||||
}
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -10,7 +10,6 @@ require (
|
|||
github.com/dgraph-io/badger/v2 v2.0.3
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/golang/protobuf v1.4.2
|
||||
github.com/gomodule/redigo v1.8.2
|
||||
github.com/google/uuid v1.1.2-0.20200519141726-cb32006e483f
|
||||
github.com/hashicorp/go-version v1.2.1
|
||||
|
@ -37,6 +36,7 @@ require (
|
|||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
|
||||
golang.org/x/text v0.3.3
|
||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1
|
||||
google.golang.org/protobuf v1.24.0
|
||||
gopkg.in/ini.v1 v1.57.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||
)
|
||||
|
|
|
@ -343,7 +343,7 @@ func TestBindingsForStruct(t *testing.T) {
|
|||
|
||||
controller3 struct {
|
||||
Emb1 embedded1
|
||||
emb2 embedded2
|
||||
emb2 embedded2 // unused
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ func resolveDependency(v reflect.Value, dest *Dependency, funcDependencies ...*D
|
|||
len(funcDependencies) > 0 && fromDependentFunc(v, dest, funcDependencies)
|
||||
}
|
||||
|
||||
func fromDependencyHandler(v reflect.Value, dest *Dependency) bool {
|
||||
func fromDependencyHandler(_ reflect.Value, dest *Dependency) bool {
|
||||
// It's already on the desired form, just return it.
|
||||
dependency := dest.OriginalValue
|
||||
handler, ok := dependency.(DependencyHandler)
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// ResultHandler describes the function type which should serve the "v" struct value.
|
||||
|
|
|
@ -15,15 +15,6 @@ func valueOf(v interface{}) reflect.Value {
|
|||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func typeOf(typ interface{}) reflect.Type {
|
||||
if v, ok := typ.(reflect.Type); ok {
|
||||
// check if it's already a reflect.Type.
|
||||
return v
|
||||
}
|
||||
|
||||
return reflect.TypeOf(typ)
|
||||
}
|
||||
|
||||
// indirectType returns the value of a pointer-type "typ".
|
||||
// If "typ" is a pointer, array, chan, map or slice it returns its Elem,
|
||||
// otherwise returns the typ as it's.
|
||||
|
|
4
iris.go
4
iris.go
|
@ -1198,7 +1198,7 @@ func (app *Application) tryInjectLiveReload() error {
|
|||
rec.SetBody(body)
|
||||
} else {
|
||||
// Just append it.
|
||||
rec.Write(scriptReloadJS)
|
||||
rec.Write(scriptReloadJS) // nolint:errcheck
|
||||
}
|
||||
|
||||
if _, has := rec.Header()[context.ContentLengthHeaderKey]; has {
|
||||
|
@ -1245,7 +1245,7 @@ func (app *Application) tryStartTunneling() {
|
|||
app.config.vhost = publicAddr[strings.Index(publicAddr, "://")+3:]
|
||||
|
||||
directLog := []byte(fmt.Sprintf("• Public Address: %s\n", publicAddr))
|
||||
app.logger.Printer.Write(directLog)
|
||||
app.logger.Printer.Write(directLog) // nolint:errcheck
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -87,7 +87,7 @@ func (l *Lexer) NextToken() (t token.Token) {
|
|||
if isLetter(l.ch) {
|
||||
// letters
|
||||
lit := l.readIdentifier()
|
||||
typ := token.LookupIdent(lit)
|
||||
typ = token.LookupIdent(lit)
|
||||
t = l.newToken(typ, lit)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ func convertBuilderFunc(fn interface{}) ParamFuncBuilder {
|
|||
var (
|
||||
val interface{}
|
||||
|
||||
panicIfErr = func(err error) {
|
||||
panicIfErr = func(i int, err error) {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("on field index: %d: %v", i, err))
|
||||
}
|
||||
|
@ -150,55 +150,55 @@ func convertBuilderFunc(fn interface{}) ParamFuncBuilder {
|
|||
switch field.Kind() {
|
||||
case reflect.Int:
|
||||
v, err := strconv.Atoi(arg)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = v
|
||||
case reflect.Int8:
|
||||
v, err := strconv.ParseInt(arg, 10, 8)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = int8(v)
|
||||
case reflect.Int16:
|
||||
v, err := strconv.ParseInt(arg, 10, 16)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = int16(v)
|
||||
case reflect.Int32:
|
||||
v, err := strconv.ParseInt(arg, 10, 32)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = int32(v)
|
||||
case reflect.Int64:
|
||||
v, err := strconv.ParseInt(arg, 10, 64)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = v
|
||||
case reflect.Uint:
|
||||
v, err := strconv.ParseUint(arg, 10, strconv.IntSize)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = uint(v)
|
||||
case reflect.Uint8:
|
||||
v, err := strconv.ParseUint(arg, 10, 8)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = uint8(v)
|
||||
case reflect.Uint16:
|
||||
v, err := strconv.ParseUint(arg, 10, 16)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = uint16(v)
|
||||
case reflect.Uint32:
|
||||
v, err := strconv.ParseUint(arg, 10, 32)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = uint32(v)
|
||||
case reflect.Uint64:
|
||||
v, err := strconv.ParseUint(arg, 10, 64)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = v
|
||||
case reflect.Float32:
|
||||
v, err := strconv.ParseFloat(arg, 32)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = float32(v)
|
||||
case reflect.Float64:
|
||||
v, err := strconv.ParseFloat(arg, 64)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = v
|
||||
case reflect.Bool:
|
||||
v, err := strconv.ParseBool(arg)
|
||||
panicIfErr(err)
|
||||
panicIfErr(i, err)
|
||||
val = v
|
||||
case reflect.Slice:
|
||||
if len(arg) > 1 {
|
||||
|
|
|
@ -23,7 +23,7 @@ type (
|
|||
logged bool
|
||||
expires time.Time
|
||||
}
|
||||
encodedUsers []encodedUser
|
||||
encodedUsers []*encodedUser
|
||||
|
||||
basicAuthMiddleware struct {
|
||||
config Config
|
||||
|
@ -75,7 +75,7 @@ func (b *basicAuthMiddleware) init() {
|
|||
for k, v := range b.config.Users {
|
||||
fullUser := k + ":" + v
|
||||
header := "Basic " + base64.StdEncoding.EncodeToString([]byte(fullUser))
|
||||
b.auth = append(b.auth, encodedUser{HeaderValue: header, Username: k, logged: false, expires: DefaultExpireTime})
|
||||
b.auth = append(b.auth, &encodedUser{HeaderValue: header, Username: k, logged: false, expires: DefaultExpireTime})
|
||||
}
|
||||
|
||||
// set the auth realm header's value
|
||||
|
@ -85,20 +85,16 @@ func (b *basicAuthMiddleware) init() {
|
|||
b.askHandlerEnabled = b.config.OnAsk != nil
|
||||
}
|
||||
|
||||
func (b *basicAuthMiddleware) findAuth(headerValue string) (auth *encodedUser, found bool) {
|
||||
if len(headerValue) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *basicAuthMiddleware) findAuth(headerValue string) (*encodedUser, bool) {
|
||||
if headerValue != "" {
|
||||
for _, user := range b.auth {
|
||||
if user.HeaderValue == headerValue {
|
||||
auth = &user
|
||||
found = true
|
||||
break
|
||||
return user, true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (b *basicAuthMiddleware) askForCredentials(ctx context.Context) {
|
||||
|
|
|
@ -41,7 +41,7 @@ func exportToFile(key *rsa.PrivateKey, filename string) error {
|
|||
},
|
||||
)
|
||||
|
||||
return ioutil.WriteFile(filename, encoded, 0644)
|
||||
return ioutil.WriteFile(filename, encoded, 0600)
|
||||
}
|
||||
|
||||
func importFromFile(filename string) (*rsa.PrivateKey, error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user