Green Function Method for Electron Gas. I General Formulation