Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nginx conf #1130

Merged
merged 23 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add comments to variables and functions
  • Loading branch information
suchen-sci committed Nov 8, 2023
commit 423867c2909e78af5d944d3029904247d3098656
1 change: 1 addition & 0 deletions cmd/client/commandv2/common/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package common

Check warning on line 18 in cmd/client/commandv2/common/spec.go

View workflow job for this annotation

GitHub Actions / analysis

should have a package comment

import (
"github.com/megaease/easegress/v2/cmd/client/general"
Expand Down Expand Up @@ -43,6 +43,7 @@
pipeline.Spec `json:",inline"`
}

// SetFilters sets the filters of PipelineSpec.
func (p *PipelineSpec) SetFilters(filters []filters.Spec) {
data := codectool.MustMarshalYAML(filters)
maps, _ := general.UnmarshalMapInterface(data, true)
Expand Down
1 change: 1 addition & 0 deletions cmd/client/commandv2/convert/nginx/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/spf13/cobra"
)

// Options contains the options for convert nginx.conf.
type Options struct {
NginxConf string
Output string
Expand Down
7 changes: 7 additions & 0 deletions cmd/client/commandv2/convert/nginx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ type ServerEnv struct {
SSLCertificateKey []*Directive `json:"ssl_certificate_key"`
}

// ProxyEnv is the environment for creating proxy.
type ProxyEnv struct {
Pass *Directive `json:"pass"`
ProxySetHeader []*Directive `json:"proxy_set_header"`
Gzip *GzipEnv `json:"gzip"`
}

// GzipEnv is the environment for creating gzip.
type GzipEnv struct {
Gzip *Directive `json:"gzip"`
GzipMinLength *Directive `json:"gzip_min_length"`
Expand Down Expand Up @@ -107,6 +109,7 @@ func newEnv() *Env {
return env
}

// Clone clones the environment.
func (env *Env) Clone() (*Env, error) {
data, err := json.Marshal(env)
if err != nil {
Expand All @@ -121,6 +124,7 @@ func (env *Env) Clone() (*Env, error) {
return &newEnv, nil
}

// MustClone clones the environment.
func (env *Env) MustClone() *Env {
newEnv, err := env.Clone()
if err != nil {
Expand All @@ -129,6 +133,7 @@ func (env *Env) MustClone() *Env {
return newEnv
}

// Update updates the environment.
func (env *Env) Update(d *Directive) {
fn, ok := env.updateFn[d.Directive]
if ok {
Expand All @@ -141,6 +146,7 @@ func (env *Env) Update(d *Directive) {
}
}

// GetServerInfo gets the server info from environment.
func (env *Env) GetServerInfo() (*ServerInfo, error) {
info := &ServerInfo{}
info.Port = 80
Expand Down Expand Up @@ -186,6 +192,7 @@ func (env *Env) GetServerInfo() (*ServerInfo, error) {
return info, nil
}

// GetProxyInfo gets the proxy info from environment.
func (env *Env) GetProxyInfo() (*ProxyInfo, error) {
p := env.Proxy
if p.Pass == nil || p.Pass.Directive != "proxy_pass" {
Expand Down
15 changes: 12 additions & 3 deletions cmd/client/commandv2/convert/nginx/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ import (
)

const (
DirectiveInclude = "include"
DirectiveHTTP = "http"
DirectiveServer = "server"
// DirectiveInclude is the include directive.
DirectiveInclude = "include"
// DirectiveHTTP is the http directive.
DirectiveHTTP = "http"
// DirectiveServer is the server directive.
DirectiveServer = "server"
// DirectiveLocation is the location directive.
DirectiveLocation = "location"
)

// Directive is the nginx directive.
type Directive = crossplane.Directive

// Directives is the nginx directives.
type Directives = crossplane.Directives

// Payload is the nginx payload.
type Payload = crossplane.Payload

func parsePayload(payload *Payload) (*Config, error) {
Expand Down
20 changes: 17 additions & 3 deletions cmd/client/commandv2/convert/nginx/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

package nginx

// Config is config for convert.
type Config struct {
Servers []*Server `json:"servers"`
}

// ServerBase is the base config for server.
type ServerBase struct {
Port int `json:"port"`
Address string `json:"address"`
Expand All @@ -31,47 +33,59 @@ type ServerBase struct {
Keys map[string]string `json:"keys"`
}

// Server is the config for server.
type Server struct {
ServerBase `json:",inline"`
Rules []*Rule `json:"rules"`
}

// ServerInfo is the info config for server.
type ServerInfo struct {
ServerBase `json:",inline"`
Hosts []*HostInfo `json:"hosts"`
}

// HostInfo is the info config for host.
type HostInfo struct {
Value string `json:"value"`
IsRegexp bool `json:"isRegexp"`
}

// Rule is the config for rule.
type Rule struct {
Hosts []*HostInfo `json:"hosts"`
Paths []*Path `json:"paths"`
}

// PathType is the type of path.
type PathType string

const (
PathTypePrefix PathType = "prefix"
PathTypeExact PathType = "exact"
PathTypeRe PathType = "regexp"
// PathTypePrefix is the prefix type of path.
PathTypePrefix PathType = "prefix"
// PathTypeExact is the exact type of path.
PathTypeExact PathType = "exact"
// PathTypeRe is the regexp type of path.
PathTypeRe PathType = "regexp"
// PathTypeReInsensitive is the case insensitive regexp type of path.
PathTypeReInsensitive PathType = "caseInsensitiveRegexp"
)

// Path is the config for path.
type Path struct {
Path string `json:"path"`
Type PathType `json:"type"`
Backend *ProxyInfo `json:"backend"`
}

// ProxyInfo is the config for proxy.
type ProxyInfo struct {
Servers []*BackendInfo `json:"servers"`
SetHeaders map[string]string `json:"setHeaders"`
GzipMinLength int `json:"gzipMinLength"`
}

// BackendInfo is the config for backend.
type BackendInfo struct {
Server string `json:"server"`
Weight int `json:"weight"`
Expand Down
Loading