#!/bin/env python
import os
import re
import os.path

''' 刪除 .pb.go 中字段的 omitempty 修飾 '''
''' Delete the 'omitempty' keyword of message field '''

pattern = re.compile(',omitempty')
root = './'

for r, dirs, files in os.walk(root):
    for file in files:
        name, ext = os.path.splitext(file)
        if ext != '.go':
            continue
        fullname = os.path.join(root, file)
        result = ''
        with open(fullname,'rt', encoding='UTF-8') as fh:
            content = fh.read()
            result, _ = re.subn(pattern, '', content)
        # replace inplace
        with open(fullname, 'wt', encoding='UTF-8') as fh:
            fh.write(result)
