We consider variation of energy of the light-like particle in the pseudo-Riemann space-time, find lagrangian, canonical momenta and forces. Equations of the critical curve are obtained by the nonzero energy integral variation in accordance with principles of the calculus of variations in mechanics. This method is compared with the Fermat's principle for the stationary gravity field and geodesics principle. Energy and momentum of the particle transferred to the gravity field is defined. The produced equations are solved for the metrics of Schwarzschild, FLRW model for the flat space and Goedel. The gravitation mass of the photon is found in central gravity field in the Newtonian limit.