github.com/zhongdalu/gf@v1.0.0/g/net/ghttp/ghttp_server_config_route.go (about)

     1  // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  package ghttp
     8  
     9  import "github.com/zhongdalu/gf/g/os/glog"
    10  
    11  func (s *Server) SetDenyIps(ips []string) {
    12  	if s.Status() == SERVER_STATUS_RUNNING {
    13  		glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
    14  		return
    15  	}
    16  	s.config.DenyIps = ips
    17  }
    18  
    19  func (s *Server) SetAllowIps(ips []string) {
    20  	if s.Status() == SERVER_STATUS_RUNNING {
    21  		glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
    22  		return
    23  	}
    24  	s.config.AllowIps = ips
    25  }
    26  
    27  func (s *Server) SetDenyRoutes(routes []string) {
    28  	if s.Status() == SERVER_STATUS_RUNNING {
    29  		glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
    30  		return
    31  	}
    32  	s.config.DenyRoutes = routes
    33  }
    34  
    35  // 设置URI重写规则
    36  func (s *Server) SetRewrite(uri string, rewrite string) {
    37  	if s.Status() == SERVER_STATUS_RUNNING {
    38  		glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
    39  		return
    40  	}
    41  	s.config.Rewrites[uri] = rewrite
    42  }
    43  
    44  // 设置URI重写规则(批量)
    45  func (s *Server) SetRewriteMap(rewrites map[string]string) {
    46  	if s.Status() == SERVER_STATUS_RUNNING {
    47  		glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
    48  		return
    49  	}
    50  	for k, v := range rewrites {
    51  		s.config.Rewrites[k] = v
    52  	}
    53  }