现在的问题是,这个业务流程少的有 4,5 个接口,多的 10 多个,我需要都在 request 函数里,写很多 if 吗?大家有什么更好的办法吗?

class Counter(object):
    def __init__(self):
        self.num = 0
        self.path = flowfilter.parse("xxx/xxx") # xxx/xxx是接口路径.

    def request(self, flow: HTTPFlow):
        if flowfilter.match(self.path, flow):
            ctx.log.info('xxx/xxx接口')
        self.num = self.num + 1
        ctx.log.info("We've seen %d flows" % self.num)

    def response(self, flow: HTTPFlow):
        if flowfilter.match(self.parh, flow):
            ctx.log.info(flow.response.get_text())
            ctx.log.info(type(flow.response.get_text()))


↙↙↙阅读原文可查看相关链接,并与作者交流